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 ?
- Laravel - chmod(storage/oauth-private.key): Operation failed: Operation not permitted
- Laravel 7.x and 6.x datatables example from scratch
- How to compress PNG image using pngquant in PHP?
- Laravel 7.x and 6.x Chart example using Charts Package
- Guzzle http client GET and POST request example in Laravel 5
- Laravel schema default current timestamp value example
- Laravel 7.x and 6.x Get Site URL Examples
- Convert object to array in laravel 7.x and 6.x example