I have an object something like:
Object {0=Object, 1=Object, 2=Object} // Output from console.log(obj.Data);
But there is no way that I can count the number of objects in object, then finally get the attribute value from the sub objects.
I have tried
console.log(obj.Data[0].length); // It does not work
console.log(obj.Data.length); // It does not work
This is a bit tricky for me. Hope you guys can help.
This question is related to
javascript
object
count
In recent browsers you can use:
Object.keys(obj.Data).length
See MDN
For older browsers, use the for-in
loop in Michael Geary's answer.
Try Demo Here
var list ={}; var count= Object.keys(list).length;
Source: Stackoverflow.com