How to get the size of a JavaScript object ? Last Updated : 12 Jan, 2024 Comments Improve Suggest changes Like Article Like Report 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() methodUsing Object.objsize() methodUsing Object.entries() methodUsing Object.values() methodUsing Object.keys() methodWe can get the size of the javascript object with the help of Object.keys() method. Create an object variable and assign values to itCreate a variable that shows the sizeCall 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); Output4 Using Object.objsize() methodCreate an object variable and assign values to itCreate a variable that shows the sizePass the object name to Object.objsize which further enters the function that calculates and returns the size and assigns it to the variable.Example: This example shows the implementation of the above-explained approach. JavaScript Object.objsize = function(obj) { let size = 0, key; for (key in obj) { if (obj.hasOwnProperty(key)) size++; } return size; }; let object1 = { "rajnish":"singh", "sanjeev":"sharma", "suraj":"agrahari", "yash":"khandelwal" }; let count = Object.objsize(object1); console.log(count); Output4 Using Object.entries() methodIn this approach, we are using Object.entries() method. after passing the given object into this method by calling length property of the object we are getting the length of the object. Example: This example shows the implementation of the above-explained approach. JavaScript let object1 = { "rajnish": "singh", "sanjeev": "sharma", "suraj": "agrahari", "yash": "khandelwal" }; let length = Object.entries(object1).length console.log(length); Output4 Using Object.values() methodIn this approach, we are using Object.values() method. after passing the given object into this method by calling length property of the object we are getting the length of the object. Example: This example shows the implementation of the above-explained approach. JavaScript let object1 = { "rajnish": "singh", "sanjeev": "sharma", "suraj": "agrahari", "yash": "khandelwal" }; let length = Object.values(object1).length console.log(length); Output4 Comment More infoAdvertise with us Next Article How to get the size of a JavaScript object ? R ravikishor Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to print the content of an object in JavaScript ? To print the content of an object in JavaScript we will use JavaScript methods like stringify, object.values and loops to display the required data. Let's first create a JavaScript Object containing some key-values as given below: JavaScript // Given Object const obj = { name: 'John', age: 30, city: 3 min read How to Get the Size of an Array in JavaScript To get the size (or length) of an array in JavaScript, we can use array.length property. The size of array refers to the number of elements present in that array. Syntaxconst a = [ 10, 20, 30, 40, 50 ] let s = a.length; // s => 5 The JavaScript Array Length returns an unsigned integer value that 2 min read How to get the last item of JavaScript object ? In this article, we will learn how to get the last item of a Javascript object. Given a JavaScript object and the task is to get the last element of the JavaScript object. This can be done by the following methods: Using Object.keys() methodUsing for loopmethodApproach 1: Use Object.keys() method to 2 min read How to get the first key name of a JavaScript object ? In JavaScript, accessing the first key name of an object involves identifying the initial property defined within that object. This concept is useful when you need to interact with or manipulate object properties in a specific order, particularly when the sequence of properties is relevant.Here we h 2 min read How to read properties of an Object in JavaScript ? Objects in JavaScript, it is the most important data type and forms the building blocks for modern JavaScript. These objects are quite different from JavaScriptâs primitive data-types(Number, String, Boolean, null, undefined, and symbol) in the sense that these primitive data-types all store a singl 2 min read Like