Test name | Executions per second |
---|---|
findIndex + splice | 1930177.9 Ops/sec |
filter | 1879276.8 Ops/sec |
indexOf + splice | 2103494.5 Ops/sec |
var arr = []
for (i = 0; i < 100; i++) {
arr.push({})
}
var item = arr[arr.length / 2]
const newArr = Object.create(arr)
newArr.splice(
newArr.findIndex(i => i === item),
1)
const newArr = Object.create(arr)
newArr.filter(i => i !== item)
const newArr = Object.create(arr)
newArr.splice(
newArr.indexOf(item),
1)
const newArr = Object.create(arr)
const index = newArr.indexOf(item)
if (index !== -1) {
newArr.splice(index, 1)
}
const newArr = Object.create(arr)
for (i = 0; i < newArr.length; i++) {
if (newArr[i] === item) {
newArr.splice(i, 1)
break
}
}