Javascript how to check object is empty or not

Chandra Prakash Pal - Jul 15 - - Dev Community

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

. . . . . . . . . . . . . . . .
Terabox Video Player