"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Javascript how to check object is empty or not

Javascript how to check object is empty or not

Published on 2024-08-01
Browse:367

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="[email protected]"

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="[email protected]"
console.log(Object.keys(user).length) // will log 2

Release Statement This article is reproduced at: https://dev.to/palchandu_dev/javascript-how-to-check-object-is-empty-or-not-1p5a?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3