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...
Do you like below Tutorials ?
- How to Open URL in New Tab using Jquery?
- Laravel 7.x and 6.x Routing Tutorial
- Ng Bootstrap Modal in Angular 8 Example
- Bootstrap 4 Datepicker in Angular 9/8 Example
- Disable Registration Route in Laravel
- Bootstrap Timepicker in Angular Example
- Count Number of Pages in PDF - PHP Script
- Digital Signature PHP Script Example