Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
reassigning an object
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
Benchmark engine:
Benchmark.js
map
7.0M/s
index
4.6M/s
View exact numbers
Test name
Executions per second
✓
map
7,028,268 Ops/sec
index
4,574,258 Ops/sec
Script Preparation code:
var array = [{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }, { id: 3, name: 'Item 3' } ]; var newObject = { id: 2, name: 'Updated Item 2' };
Tests:
map
var index = array.findIndex(item => item.id === newObject.id); if (index !== -1) { array[index] = newObject; }
index
var index = array.findIndex(item => item.id === newObject.id); // Only proceed if the item is found 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; }