如何在JavaScript中找到数组中某个项目的重复次数?

时间:2019-03-27 12:03:40

标签: javascript arrays

如何找到该数组中重复1(例如)的时间?

myArray = [1, 2, 3, 1, 4, 5, 1, 6];

1 个答案:

答案 0 :(得分:0)

尝试此解决方案

 function getOccurrence(myArray, value) {
        var count = 0;
        myArray .forEach((val) => (val === value && count++));
        return count;
    }
相关问题