Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Add property to objects
(version: 0)
Add a property to objects in an array
Comparing performance of:
for loop vs map vs forEach
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
for loop
let a = [{ a: 1, b: 'bar' }, { a: 2, b: 'foo' }, { a: 3, b: 'baz' }] for(let i=0, l=a.length; i<l; i++) { a[i].c = 'zzz' }
map
let a = [{ a: 1, b: 'bar' }, { a: 2, b: 'foo' }, { a: 3, b: 'baz' }] a.map(v => { return { ...v, c: 'zzz' } })
forEach
let a = [{ a: 1, b: 'bar' }, { a: 2, b: 'foo' }, { a: 3, b: 'baz' }] a.forEach(v => { v.c = 'zzz' })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
for loop
map
forEach
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Set: Array.from vs Spread
set.add vs array.push
Object.prototype.hasOwnProperty vs Object in vs Object[] vs Array.indexOf vs Array.includes vs Set.has
array of objects assign (array.length) vs push (tiny array)
add vs object
Comments
Confirm delete:
Do you really want to delete benchmark?