Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Iterate over 2 object with merge 2
(version: 1)
Comparing performance of:
for..in with hasOwnProperty() vs Object.keys() + Array.forEach()
Created:
7 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var o1 = {}; var o2 = {}; for(var i=0; i<5000; i++) { o1[`id${i}`] = {i}; o1[`id${i}2`] = {i}; } const out = {} var assignIn = (key) => { out[key] = {} Object.assign(out[key], o1[key], o2[key]) }
Tests:
for..in with hasOwnProperty()
for (const key in o1) { if (o1.hasOwnProperty(key)) { assignIn(key) } } for (const key in o2) { if (o2.hasOwnProperty(key)) { assignIn(key) } }
Object.keys() + Array.forEach()
Object.keys(o1) .concat(Object.keys(o2)) .forEach(assignIn)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
for..in with hasOwnProperty()
Object.keys() + Array.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:
Object.entries vs Object.keys vs for...in
Object.values vs for in loop vs for loop v2 borys
Array of Objects to Object with keys Object.fromEntries v Object.assign
For in vs Object.entries 2
array.map() with spread vs for-loop v2
Comments
Confirm delete:
Do you really want to delete benchmark?