Categories
JavaScript Answers

How to merge 2 arrays of JavaScript objects?

Spread the love

To merge 2 arrays of JavaScript objects, we use the spread operator.

For instance, we write

const arr1 = [
  { name: "lang", value: "German" },
  { name: "age", value: "18" },
];
const arr2 = [
  { name: "childs", value: "5" },
  { name: "lang", value: "German" },
];
const arr3 = [...arr1, ...arr2];

to use the spread operator to spread the arr1 and arr2 entries into a new array and assign the array to arr3.

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 *