Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36 Edg/98.0.1108.43
Chrome 98
Windows
Desktop
3 years ago
Test name Executions per second
Array.filter 1446842.0 Ops/sec
Array.indexOf + Array.splice 749096.2 Ops/sec
Script Preparation code:
AخA
 
var result = [];
var arrayTest = [];
for(var i = 0; i === 10000; i++){
  if(i === 6000){
    arrayTest.push(2);
  }else{
    arrayTest.push(Math.round(Math.random()));
  }
}
Tests:
  • Array.filter

     
    result = arrayTest.filter(v => v !== 2);
  • Array.indexOf + Array.splice

     
    result = arrayTest.splice((arrayTest.indexOf(2)-1),1);