Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0
Firefox 104
Windows
Desktop
2 years ago
Test name Executions per second
Splice 265120.0 Ops/sec
Copy to new 43305.0 Ops/sec
Script Preparation code:
x
 
var randomArray=Array.from({length: 1000}, () => Math.floor(Math.random() * 100));
Tests:
  • Splice

     
    for (let i = randomArray.length - 1; i >= 0; --i) {
      if (randomArray[i] !=  1) {
        continue;
      }
      randomArray.splice(i, 1);
    }
    return randomArray;
  • Copy to new

     
    var newArray = [];
    for (let i = randomArray.length - 1; i >= 0; --i) {
      if (randomArray[i] ==  1) {
        continue;
      }
      newArray.push(randomArray[i]);
    }
    return newArray;