Sometimes, we want to concatenate properties from multiple JavaScript objects.
In this article, we’ll look at how to concatenate properties from multiple JavaScript objects.
How to concatenate properties from multiple JavaScript objects?
To concatenate properties from multiple JavaScript objects, we can use the object spread syntax.
For instance, we write
const obj1 = { 1: 11, 2: 22 };
const obj2 = { 3: 33, 4: 44 };
const obj3 = { ...obj1, ...obj2 };
to put the properties of obj1
and obj2
into a new object with the spread operator and assign the new object to obj3
.
Conclusion
To concatenate properties from multiple JavaScript objects, we can use the object spread syntax.