Check if Object is Empty

Posted on Updated on by Gergő D. Nagy

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!