CoreUI ONE — 250+ PRO components and 25+ admin templates for React, Angular, Vue, Bootstrap and Next.js, plus Data Grid, Scheduler, 4,300+ PRO icons and the Next.js boilerplate. One license. → See what you get

How to check if an object is empty in JavaScript

Checking whether an object is empty is essential for form validation, API response handling, and conditional rendering in JavaScript applications. As the creator of CoreUI, a widely used open-source UI library, I’ve implemented empty object checks in countless production components. From my expertise, the most reliable approach is using Object.keys() to check the length of enumerable properties. This method works consistently across all modern browsers and handles edge cases properly.

Use Object.keys() to check if an object has any enumerable properties.

const isEmpty = Object.keys(obj).length === 0

Here Object.keys(obj) returns an array of all enumerable property names from the object. If the array length equals 0, the object has no properties and is considered empty. This method correctly identifies {} as empty while properly handling objects with inherited properties or non-enumerable properties.

Best Practice Note:

This is the same approach we use in CoreUI components for form validation and conditional rendering. For objects that might be null or undefined, combine with a nullish check: obj && Object.keys(obj).length === 0 to avoid errors.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
Passing props to child components in React function components
Passing props to child components in React function components

How to loop inside React JSX
How to loop inside React JSX

How to validate an email address in JavaScript
How to validate an email address in JavaScript

What is the difference between typeof and instanceof in JavaScript
What is the difference between typeof and instanceof in JavaScript