How do you return the number of zeros in an array in JavaScript?
For example this array has numbers [ 2, 3, 0 , 9, 0] and it should output to 2 zeros.
Thanks for responding! I'm still a newbie at JavaScript.
How do you return the number of zeros in an array in JavaScript?
For example this array has numbers [ 2, 3, 0 , 9, 0] and it should output to 2 zeros.
Thanks for responding! I'm still a newbie at JavaScript.
Try this there could be better solutions also.
var arr = [2, 3, 0 , 9, 0];
var zeros = arr.filter(function (el) {
return el == 0;
});
console.log(zeros.length)