猿问
js 统计空格次数
var a = ["a","","","","b","","","c",""];
计算后的结果是
{
a:3,b:2,c:1
}
慕后森
浏览 509
回答 1
1回答
回首忆惘然
var a = ['a', '', '', '', 'b', '', '', 'c', ''];let b = a.reduce((d, v) => void (v ? (d.k = v) && (d.v[v] = 0) : d.v[d.k] += 1) || d, {v: {}, k: ''}).v;console.log(b);
0
0
0
随时随地看视频
慕课网APP
相关分类
JavaScript
我要回答