DEV Community

freecoderzhaoshuai
freecoderzhaoshuai

Posted on

Choose if array element repeats itself twice — Javascript [duplicate]

var arr = [0, 1, 2, 2, 3, 3, 5];

var dups = arr.filter ( (v,i,a) => a.indexOf(v) < i );

console.log(dups);

[
2,
3
]

when v=2, a.indexof(2)=2,but i=3
so filter 2 to the dups

Top comments (0)