Categories
JavaScript Answers

How to concatenate two JSON objects with JavaScript?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.