Ask any question about JavaScript here... and get an instant response.
Post this Question & Answer:
How can I check if an object is empty in JavaScript?
Asked on Apr 20, 2026
Answer
To check if an object is empty in JavaScript, you can use the `Object.keys()` method to get an array of the object's keys and then verify if the array's length is zero.
<!-- BEGIN COPY / PASTE -->
const isEmpty = (obj) => Object.keys(obj).length === 0;
const myObject = {};
console.log(isEmpty(myObject)); // true
const anotherObject = { key: 'value' };
console.log(isEmpty(anotherObject)); // false
<!-- END COPY / PASTE -->Additional Comment:
✅ Answered with JavaScript best practices.- This method works for plain objects and checks if there are any enumerable properties.
- It does not consider non-enumerable properties or properties from the prototype chain.
- Suitable for most use cases where you need to determine if an object has no own properties.
Recommended Links:
