Counting the occurrences / frequency of array elements

前端 未结 30 2044
甜味超标
甜味超标 2020-11-21 06:47

In Javascript, I\'m trying to take an initial array of number values and count the elements inside it. Ideally, the result would be two new arrays, the first specifying each

30条回答
  •  你的背包
    2020-11-21 07:14

    I think this is the simplest way how to count occurrences with same value in array.

    var a = [true, false, false, false];
    a.filter(function(value){
        return value === false;
    }).length
    

提交回复
热议问题