Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Array with Objects loop
Loop through an array of objects and change one property
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0
Browser:
Firefox 135
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
For
241030.5 Ops/sec
Foreach
152270.8 Ops/sec
For-in
13017.0 Ops/sec
For-of
145430.5 Ops/sec
map
118894.8 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const array = Array.from({ length: 1000 }, function(_v, index) { return { index } } )
Tests:
For
for (let i = 0; i < array.length; i++) { let item = array[i] item.index = i + 1 } console.log('for', array)
Foreach
array.forEach(function(item, i) { item.index = i + 1 }); console.log('forEach', array)
For-in
for (let i in array) { let item = array[i] item.index = i + 1 } console.log('for-in', array)
For-of
let i = 0 for (let item of array) { item.index = i + 1 i++ } console.log('for-of', array)
map
array.map((item,i) => { item.index = i + 1 }) console.log('map', array)