Json Object Length in Javascript Example

February 22, 2019 | Category : Javascript JQuery

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

we will use Object class with keys() and get length. keys() will take one argument as json object. then you can simply get length. In javascript you can get object keys length using Object class.

we can simply get like as bellow quick example:

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

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

you can see full example bellow:

Example:

<!DOCTYPE html>

<html>

<head>

<title>Json Object Length in Javascript Example - HDTuto.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': 'HDtuto.com', 'description': 'HDtuto.com'},

'1' : {'title': 'ItsolutionStuff.com', 'description': 'ItsolutionStuff.com'}

};

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

console.log(countKey);

</script>

</body>

</html>

I hope you found your best example...