Home > Web Front-end > JS Tutorial > Javascript how to check object is empty or not

Javascript how to check object is empty or not

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2024-07-18 20:13:06
Original
1070 people have browsed it

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!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template