Sometimes, we want to concatenate two JSON objects with JavaScript.
In this article, we’ll look at how to concatenate two JSON objects with JavaScript.
How to concatenate two JSON objects with JavaScript?
To concatenate two JSON objects with JavaScript, we can use the object spread operator.
For instance, we write
const obj = { ...sourceObj1, ...sourceObj2 };
to put the properties of sourceObj1 and sourceObj2 into the new object after making a shallow copy of the 2 objects.
Then we assign the new object to obj.
Conclusion
To concatenate two JSON objects with JavaScript, we can use the object spread operator.