Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
splice vs filter (delete from array)
Comparison of "splice" and "filter" methods for removing an element from an array.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Browser:
Chrome 146
Operating system:
Windows
Device Platform:
Desktop
Date tested:
4 months ago
indexOf, splice
217K/s
indexOf, splice, check
212K/s
findIndex, splice
189K/s
filter
174K/s
for, splice
132K/s
View exact numbers
Test name
Executions per second
✓
indexOf, splice
216,826 Ops/sec
indexOf, splice, check
211,795 Ops/sec
findIndex, splice
189,296 Ops/sec
filter
174,215 Ops/sec
for, splice
131,508 Ops/sec
Script Preparation code:
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 } }