How to Check if an Object is Empty with JavaScript

This is an empty object:

const emptyObject = {}

But how do you check if an object is empty with JavaScript?

By using the Object.entries() function.

Here’s another empty object:

const someObject = {}

Now use the Object.entries() function on it:

Object.entries(someObject)

To log out the result:

console.log(Object.entries(someObject))
// [] (empty array)

If an object is empty the result is an empty array [].


Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊

Kofi

Share & Discuss on