slice VS splice VS filter: deleting one item

100k list
3 years ago
User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62
Test name Executions per second
slice 96.0 Ops/sec
splice 580.2 Ops/sec
filter 59.9 Ops/sec
Script Preparation code:
AخA
 
var list = [];
for (var i = 0; i < 1000 * 1000; i++) {
  list.push(i);
}
Tests:
  • slice

     
    list = [
      ...list.slice(0, 50000),
      ...list.slice(50000 + 1)
    ];
  • splice

    x
     
    newList = [...list];
    newList.splice(50000, 1);
  • filter

     
    newList = list.filter(i => i !== 50000);
Open this result on MeasureThat.net