Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
reassigning an object with 10000 objects
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
index
48798.5 Ops/sec
map
33361.7 Ops/sec
Script Preparation code:
var array = []; for (var i = 1; i <= 10000; i++) { array.push({ id: i, name: `Item ${i}` }); } var newObject = { id: 8868, name: 'Updated Item 2' };
Tests:
index
var index = array.findIndex(item => item.id === newObject.id); var updatedArray; if (index !== -1) { updatedArray = [ ...array.slice(0, index), // Elements before the updated item newObject, // The updated item ...array.slice(index + 1) // Elements after the updated item ]; } else { // If the item isn't found, the array remains unchanged updatedArray = array; }
map
var arr = array.map(item => { if (item.id === newObject.id) { return newObject; } return item; });