How to count duplicate value in an array in javascript

前端 未结 28 1313
后悔当初
后悔当初 2020-11-22 06:07

Currently, I got an array like that:

var uniqueCount = Array();

After a few steps, my array looks like that:

uniqueCount =          


        
28条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 06:26

    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                                      
    

提交回复
热议问题