Raymon Schouwenaar

How to check if a Object is empty with Vanilla JavaScript

Written by Raymon on , time to read ~1 minutes.

Well I can make a very long description about how to check if a object is empty, but this could be very short!

    
        
    function isEmptyObject(objectInput) {
        for ( name in objectInput) {
            return false;
        }
        return true;
    }

    

Simply, if the for-in loop is finding any property, it will start to iterate over the first property, but after this it will return false. But when it won’t loop it directly returns true.

Nothing difficult! But very handy util function to use in if-else statements 👍

comments powered by Disqus

Readmore

CSS Grid Layout Metro design blocks

The times have come that we don’t have to fiddle around with Floats and Tables anymore! Flexbox is already an established term in the industry of Frontend Developers.

3 ways to loop over Object properties with Vanilla JavaScript

It happens a lot that you need to loop over an Array with JavaScript Objects! But sometimes you just don’t know what kind of properties that Object has. Lucky we are that JavaScript offers a few ways of looping over JavaScript Object properties.