小编Pro*_*ess的帖子

多次查找数组中相同元素的索引

我想在没有方法的同一个数组中找到一个元素的POSITIONS,一个算法......

示例:

var a = [1,2,2,1,4,5,6]
to display positions of 1 : position 0 and 3
to display positions of 2 : position 1 and 2
Run Code Online (Sandbox Code Playgroud)

到目前为止我做了什么:

function count(array,element){
    while(element in array){
        return array.indexOf(element);
    }
}
Run Code Online (Sandbox Code Playgroud)

javascript arrays algorithm

0
推荐指数
1
解决办法
2088
查看次数

标签 统计

algorithm ×1

arrays ×1

javascript ×1