js数组按某一项统计求老司机指点!

数组如下所示,怎么统计出inputer最多的三个名字和重复的次数,求一个算法
vardata=[
{id:"001",inputer:"张三",inputer_code:"003"},
{id:"002",inputer:"诺一",inputer_code:"001"},
{id:"003",inputer:"张三",inputer_code:"003"},
{id:"004",inputer:"诺一",inputer_code:"001"},
{id:"005",inputer:"李四",inputer_code:"004"},
{id:"006",inputer:"胡六",inputer_code:"001"},
{id:"007",inputer:"张三",inputer_code:"003"},
{id:"008",inputer:"诺一",inputer_code:"001"},
{id:"009",inputer:"王五",inputer_code:"003"},
{id:"010",inputer:"王五",inputer_code:"001"},
{id:"011",inputer:"李四",inputer_code:"004"},
{id:"012",inputer:"诺一",inputer_code:"001"}
];
谢谢!
一只萌萌小番薯
浏览 316回答 2
2回答

沧海一幻觉

data.reduce(function(prev,next){prev[next.inputer]=(prev[next.inputer]+1)||1;returnprev;},{});

繁花不似锦

次数有了,接下来就简单了constresult=data.reduce((total,cur)=>{total[cur.inputer]=total[cur.inputer]?total[cur.inputer]+1:1;returntotal},{})
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript