Reputation: 9165
i have an array
var fruits = [];
fruits[5] ="apple";
fruits[85] ="pinapple";
How can i get the count of array as 2 in node.js
Upvotes: 0
Views: 2978
Reputation: 29317
While
fruits.length
will give you the highest index plus 1 (86)
you can use
fruits.filter(function(x){return x !== 'undefined'}).length
to get the number of non-undefined elements in the arrya
Upvotes: 3