JavaScriptEasy
How do you reliably determine whether an object is empty?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
To reliably determine whether an object is empty, you can use Object.keys() to check if the object has any enumerable properties. If the length of the array returned by Object.keys() is zero, the object is empty.
js
const isEmpty = (obj) => Object.keys(obj).length === 0;
const obj = {};
console.log(isEmpty(obj)); // true
