DEV Community

Discussion on: Different ways to check If Object is empty or not

Collapse
 
ag251994 profile image
abhishek gupta

Great article. Just a small question, which one will be the best approach?

Collapse
 
anders profile image
Anders

I'd love to see a benchmarked comparison : )

Collapse
 
awesome_aj1298 profile image
Arpit Jain

Thanks 😊, The best approach is utility function

function isEmpty(obj) {
    for(var prop in obj) {
        if(obj.hasOwnProperty(prop))
            return false;
    }

    return true;
}
Collapse
 
vetrivel profile image
Vetrivel p

I am not understood, please explain brielfy, I am beginner in JS.