How to find the Json Object Length in Javascript?

In this example, I will see how to get length of json object in javascript. i can get json object size by using Object.keys method in jquery. i can easily get size of json object & count object lengths using javascript function.

Json Object Length in Javascript Example

i will use Object class with keys() as well as get length. keys() will take single argument as json object. then you can easy get lengths. In javascript Example you can get object keys lengths using Object class.

Read Also:  Simple JavaScript Get current url Example

i can simply get like as bellow best example with syntax:

var countKey = Object.keys(jsonObj).length;

As you can see above example i have to simple give object array on keys function and get lengths key.

you can see full example source code bellow: jQuery Ajax Call to Laravel Script with JSON Return

Example: Json Object Lengths in Javascript Example

<!DOCTYPE html>
<html>
<head>
  <title>Json Object Length in Javascript Example - www.pakainfo.com</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>

<script type="text/javascript">
  var jsonObj = {
    '0' : {'title': 'pakainfo.com', 'description': 'pakainfo.com'},
    '1' : {'title': 'infinityknow.com', 'description': 'infinityknow.com'}
  };

  var countKey = Object.keys(jsonObj).length;
  console.log(countKey);
</script>
</body>
</html>

Using Object.keys()

i can easy to get json lengths like as bellow best example.

let a = {
   name: "Virat",
   age: 54,
   city: "CSK Team"
}
console.log(Object.keys(a).length)

results

3

I hope you get an idea about JSON lengths – JavaScript.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  Simple Print PHP Hello World program From scratch

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  How to Increment and Decrement Column Value in Laravel 6?
  2. Read Also:  Laravel 5.8 AJAX Tutorial Example From Scratch
  3. Read Also:  Multiple Image upload preview remove option
  4. Read Also:  Login and Signup System using PHP MySQLi
  5. Read Also:  Generate XML Save File Using PHP And MySQL database
  6. Read Also:  Angular 6 Registration and Login System Example Tutorial
  7. Read Also:  download csv file in php example
  8. Read Also:  Laravel MySQL Get Last Inserted ID
  9. Read Also:  Multiple Image upload preview remove option
  10. Read Also:  Generate XML Save File Using PHP And MySQL database