How to use Object.keys() method In Javascript
- We can get the size of the javascript object with the help of Object.keys() method.
- Create an object variable and assign values to it
- Create a variable that shows the size
- Call the Object.keys(object-name).length and assign it to the variable (in step 2).
Syntax:
Object.keys(object_name);
Example: To get the size of a javascript object by Object.keys() method.
JavaScript
let object1= { "rajnish" : "singh" , "sanjeev" : "sharma" , "suraj" : "agrahari" , "yash" : "khandelwal" }; let count= Object.keys(object1).length; console.log(count); |
Output
4
How to get the size of a JavaScript object ?
In this article, we will see the methods to find the size of a JavaScript object.
These are the following ways to solve the problem:
Table of Content
- Using Object.keys() method
- Using Object.objsize() method
- Using Object.entries() method
- Using Object.values() method