To check if a JavaScript object is empty, you can either use the Object.entries() method or the Object.keys() method.

// Object.entries()
Object.entries({}).length === 0               // true
Object.entries({ name: 'Atta' }).length === 0 // false

// Object.keys()
Object.keys({}).length === 0                 // true
Object.keys({ name: 'Atta' }).length === 0   // false

Alternatively, you could also use the Object.getOwnPropertyNames method to verify if an object contains any property:

Object.getOwnPropertyNames({}).length === 0             // true

Object.getOwnPropertyNames({name: 'Atta'}).length === 0 // false

You can also create a helper function and add it to the object’s prototype:

Object.prototype.isEmpty = function () {
    return Object.keys(this).length == 0
}

Now just call the Object.isEmpty() function whenever you want to check if an object is empty or not:

const obj = {}
obj.isEmpty() // true

const user = { name: 'Atta' }
user.isEmpty() // false