I have an array:
[1, 2, 3, 5, 2, 8, 9, 2]
I would like to know how many 2
s are in the array.
What is the most elegant way to do it in JavaScript without looping with for
loop?
Very simple:
var count = 0;
for(var i = 0; i < array.length; ++i){
if(array[i] == 2)
count++;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments