Given following array:
var arr = [undefined, undefined, 2, 5, undefined, undefined];
I\'d like to get the count of elements which are>
Loop and count in all browsers:
var cnt = 0; for (var i = 0; i < arr.length; i++) { if (arr[i] !== undefined) { ++cnt; } }
In modern browsers:
var cnt = 0; arr.foreach(function(val) { if (val !== undefined) { ++cnt; } })