Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JavaScript merge many properties
(version: 0)
Comparing performance of:
Using the spread operator vs Using Object.assign vs Using assignment
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const objWithManyProps1 = (function () { const obj = {} for (let i = 0; i < 100000; i++) { obj[`prop${i}`] = i } return obj })() const objWithManyProps2 = (function () { const obj = {} for (let i = 0; i < 100000; i++) { obj[`prop${i}`] = i } return obj })()
Tests:
Using the spread operator
const finalObject = { ...objWithManyProps1, ...objWithManyProps2 };
Using Object.assign
const finalObject = Object.assign({}, objWithManyProps1, objWithManyProps2);
Using assignment
const finalObject = {}; for (const key in objWithManyProps1) { finalObject[key] = objWithManyProps1[key]; } for (const key in objWithManyProps2) { finalObject[key] = objWithManyProps2[key]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Using the spread operator
Using Object.assign
Using assignment
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!
Comments
Confirm delete:
Do you really want to delete benchmark?