Test name | Executions per second |
---|---|
Using indexOf | 59.9 Ops/sec |
Using lastIndexOf | 53.4 Ops/sec |
Using a Set | 600.1 Ops/sec |
var array = [];
for (let i = 0; i < 100000; i++) {
array.push(Math.floor((Math.random() * 10) + 1));
}
array.filter((item, index) => array.indexOf(item) != index);
array.filter((item, index) => array.lastIndexOf(item) != index);
[new Set(array)]