Categories
JavaScript Answers

How to concatenate properties from multiple JavaScript objects?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *