Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
findIndex vs map and create new array
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
findindex
11662327.0 Ops/sec
map
9959783.0 Ops/sec
Tests:
findindex
var test = [{name: 'test1', id: 1}, {name: 'test2', id: 2}, {name: 'test3', id: 3}]; var index = test.findIndex(i => i.id === 3); const updatedObj = { ...test[index], name: 'REPLACED' }; const result = [ ...test.slice(0, index), updatedObj, ...test.slice(index + 1) ];
map
var test = [{name: 'test1', id: 1}, {name: 'test2', id: 2}, {name: 'test3', id: 3}]; var index = test.map(t => t.id).indexOf(3); const updatedObj = { ...test[index], name: 'REPLACED' }; const result = [ ...test.slice(0, index), updatedObj, ...test.slice(index + 1) ];