-3

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.

1 Answers1

1

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)
Mritunjay
  • 25,338
  • 7
  • 55
  • 68