Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Chrome 108
Windows
Desktop
2 years ago
Test name Executions per second
Using indexOf 59.9 Ops/sec
Using lastIndexOf 53.4 Ops/sec
Using a Set 600.1 Ops/sec
Script Preparation code:
AخA
 
var array = [];
for (let i = 0; i < 100000; i++) {
   array.push(Math.floor((Math.random() * 10) + 1));
}
Tests:
  • Using indexOf

     
    array.filter((item, index) => array.indexOf(item) != index);
  • Using lastIndexOf

     
    array.filter((item, index) => array.lastIndexOf(item) != index);
  • Using a Set

     
    [...new Set(array)]