Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Remove an item from array; indexOf + splice vs filter
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser:
Chrome 122
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
filter
14.4M/s
indexOf + splice
5.0M/s
View exact numbers
Test name
Executions per second
✓
filter
14,390,215 Ops/sec
indexOf + splice
5,036,380 Ops/sec
Script Preparation code:
var arr = []; for (var i = 0; i < 10000; i++) { arr.push(Math.floor(Math.random() * 1000)); } var itemToRemove = arr[Math.floor(Math.random() * 10000)]
Tests:
indexOf + splice
var result = arr.splice(arr.indexOf(itemToRemove), 1)
filter
var result = arr.filter(el => el !== itemToRemove)