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 ?
- Angular Use CKEditor Example Tutorial
- How to Use Multiple Select Dropdown in Laravel?
- Angular 9 Image Upload with Crop Example
- Files Upload on Button Click in PHP Dropzone Example
- PHP Dropzone Allow only One File to Upload Example
- PHP Dropzone Allow only Images to Upload Example
- PHP Dropzone Delete Uploaded File Example
- Livewire CRUD Laravel 7 Example