JS元素分组统计

var arr = [ 'Car', 'Car', 'Truck', 'Boat', 'Truck' ];
var hist = {};
arr.map( function (a) { if (a in hist) hist[a] ++; else hist[a] = 1; } );
console.log(hist);

 

posted @ 2020-11-26 18:14  xdsax  阅读(1116)  评论(0编辑  收藏  举报