Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0
Firefox 118
Windows
Desktop
one year ago
Test name Executions per second
findIndex + splice 1930177.9 Ops/sec
filter 1879276.8 Ops/sec
indexOf + splice 2103494.5 Ops/sec
Script Preparation code:
x
 
var arr = []
for (i = 0; i < 100; i++) {
    arr.push({})
}
var item = arr[arr.length / 2]
Tests:
  • findIndex, splice

     
    const newArr = Object.create(arr)
    newArr.splice(
      newArr.findIndex(i => i === item),
      1)
  • filter

     
    const newArr = Object.create(arr)
    newArr.filter(i => i !== item)
  • indexOf, splice

     
    const newArr = Object.create(arr)
    newArr.splice(
      newArr.indexOf(item),
      1)
  • indexOf, splice, check

     
    const newArr = Object.create(arr)
    const index = newArr.indexOf(item)
    if (index !== -1) {  
        newArr.splice(index, 1)
    }
  • for, splice

     
    const newArr = Object.create(arr)
    for (i = 0; i < newArr.length; i++) {
      if (newArr[i] === item) {  
        newArr.splice(i, 1)
        break
      }
    }