<!DOCTYPE html>
<html>
<body>
<table>
<tbody id="tbody"></tbody>
</table>
<script>
var obj = [{ "key": "apple", "value": 1.90},
{ "key": "berry", "value": 1.7},
{ "key": "banana", "value": 1.5},
{ "key": "cherry", "value": 1.2}
];
var a= Object.keys(obj).length;
document.write(a);
</script>
</body>
</html>
output: 4 i.e here it returns total number of objects inside the array.
<html>
<body>
<table>
<tbody id="tbody"></tbody>
</table>
<script>
var obj = [{ "key": "apple", "value": 1.90},
{ "key": "berry", "value": 1.7},
{ "key": "banana", "value": 1.5},
{ "key": "cherry", "value": 1.2}
];
var a= Object.keys(obj).length;
document.write(a);
</script>
</body>
</html>
output: 4 i.e here it returns total number of objects inside the array.
No comments:
Post a Comment