Home >Web Front-end >JS Tutorial >Javascript how to check object is empty or not
In JavaScript everything start with object. Object has vital role while working with JavaScript.
We define object with two curly braces like
const user={};
later can add key value pairs in it like
user.name="User"
user.email="user@gmail.com"
But mostly we have to check that object is empty or not. So let's check it
const user={};
console.log(Object.keys(user).length) // will log 0
user.name="User"
user.email="user@gmail.com"
console.log(Object.keys(user).length) // will log 2
The above is the detailed content of Javascript how to check object is empty or not. For more information, please follow other related articles on the PHP Chinese website!