📌  相关文章
📜  javascript 计算数组中某个值的出现次数 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:15.989000             🧑  作者: Mango

代码示例1
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);

// Examples
countOccurrences([2, 1, 3, 3, 2, 3], 2);                // 2
countOccurrences(['a', 'b', 'a', 'c', 'a', 'b'], 'a');  // 3