I have javascript Array that looks like 
The problem is Object.mappings has 3 elements which are clearly printed in console with console.log(), but when I try to find length of the array it returns 0. I tried stringifying the array and it just prints "[]".
what Am I doing wrong here?
You can use length property only if array contains elements associated with indexes. If it is associative array then length property will return 0. You can count elements by yourself using this code:
function len(arr) {
var count = 0;
for (var k in arr) {
if (arr.hasOwnProperty(k)) {
count++;
}
}
return count;
}
Then you can count elements of "mappings" array using len(mappings)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With