javascript - How to count the number of certain element in an array? -


if have array [1, 2, 3, 5, 2, 8, 9, 2], check how many 2s there in array. elegant way in javascript without looping for loop?

very simple:

var count = 0; for(var = 0; < array.length; ++i){     if(array[i] == 2)         count++; } 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -