Check if Object is Empty

JavaScriptPosted on

With this little snippet, you can easily check if the given object is empty or not. You may wrap it in a function to use it more globally.

let obj = {};
Object.getOwnPropertyNames(obj).length === 0; // 

let obj = {a: 'b'};
Object.getOwnPropertyNames(obj).length === 0; // Not Empty

Need a web developer? Maybe we can help, get in touch!

Looking for web dev job?
You can check them on Jooble.

To see and write comments, you must allow the related (Disqus) cookies. For more information, please visit our privacy policy page.

Similar Posts

More content in JavaScript category