Skip to content
JsDevLife
Menu
  • Home
  • Leetcode in JS
  • About me
  • Contact Us
Menu

Mastering in Javascript | get size of json object

Posted on January 23, 2019 by Vikas Kad

Mastering in Javascript:

As a JavaScript developer, we have to handle multiple conditions with objects to match our requirements.
So sometimes we need to find the length of the object.

Get the size of JSON object:

To get the size of an array we use array.length but for the object, it won’t work, let’s see it by example.
  var arrObj = {'first_name':'Vikas', 'last_name:':'Kad','age': 26}
The output will be like this:
get size of json object
If you see output arrObj.length shows undefined  
To find the size of object we will find it using Object property.
  var count = Object.keys(arrObj).length;  console.log('Object length is: ',count);

>>> Output 
Object length is: 3

So inshort by using Object.keys() Javascript Object function you can find the size of object easily.

The Object.keys() method returns an array of a given object’s own property names in the same order as we get with a normal loop.
That’s it, comment if you have any doubts.


Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Solving LeetCode Problem 79 – Word Search in JavaScript
  • Solving LeetCode Problem 48: Rotate Image using JavaScript
  • Solving the “Container With Most Water” LeetCode Problem in JavaScript – A Comprehensive Guide
  • LeetCode Solution: 54: Spiral Matrix in JavaScript
  • Solution to LeetCode Problem 31. Next Permutation in JavaScript

Archives

  • 2023 (5)
  • 2022 (20)
  • 2021 (2)
  • 2020 (4)
  • 2019 (14)
  • 2018 (17)

Categories

  • blockchain development
  • Blog
  • crystal
  • flutter
  • flutter.io
  • GitHub
  • Installation
  • Ionic Framework
  • javascript
  • leetcode-in-js
  • masteringInJavasript
  • mcqs
  • MongoDB
  • nodejs
  • Object Oriented Javacript
  • python
  • smart contracts
  • visual studio

Quick Links

  • Home
  • Leetcode in JS
  • About me
  • Contact Us

Terms of service

  • Terms Of Service
  • Disclaimer
©2023 JsDevLife | Design: Newspaperly WordPress Theme