If you want to merge 2 arrays of objects in JavaScript. You can use this one line trick

Array.prototype.push.apply(arr1,arr2);

For Example

var arr1 = [{name: "lang", value: "English"},{name: "age", value: "18"}];
var arr2 = [{name : "childs", value: '5'}, {name: "lang", value: "German"}];

Array.prototype.push.apply(arr1,arr2); 

console.log(arr1);  // final merged result will be in arr1

Output:

[{"name":"lang","value":"English"},
{"name":"age","value":"18"},
{"name":"childs","value":"5"},
{"name":"lang","value":"German"}]
Answer from Jahanzaib Aslam on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › concat
Array.prototype.concat() - JavaScript | MDN
The concat() method of Array instances is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.
🌐
Go Make Things
gomakethings.com › merging-arrays-and-objects-with-vanilla-javascript
Merging arrays and objects with vanilla JavaScript | Go Make Things
You can alternatively use the spread operator (...) to create a new array with the values of your other arrays. ... You can use the Object.assign() method to merge two or more objects together.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-merge-two-different-arrays-of-objects-with-unique-values-only-in-javascript
How to Merge two Different Arrays of Objects with Unique Values in JavaScript? - GeeksforGeeks
August 5, 2025 - The reduce() method is used to iteratively merge array2 into array1. The some() method is employed to check if an object with the same id already exists in the accumulated array.
🌐
Medium
daviddalbusco.medium.com › merge-two-objects-and-array-to-object-in-javascript-79580583727a
Merge Two Objects And Array To Object In JavaScript | by David Dal Busco | Medium
April 3, 2020 - Thanks to the introduction of Spread Operator in ES6, it is now more than ever before really easy to merge two objects.
🌐
JavaScript in Plain English
javascript.plainenglish.io › efficiently-merging-arrays-in-javascript-32993788a8b2
How to Efficiently Merge Arrays in JavaScript | by Chad Campbell | JavaScript in Plain English
February 18, 2022 - These three implementations will serve as the foundation for the performance analysis shown in the next section. Let’s begin. The concat function is the de-facto standard for merging arrays in JavaScript.
Find elsewhere
🌐
Greenroots
blog.greenroots.info › 5-ways-to-merge-arrays-in-javascript-and-their-differences
5 ways to merge arrays in JavaScript and their differences
October 15, 2021 - JavaScript Array object has several practical methods. One of them is the concat() method. The primary usage of the concat method is to merge two arrays.
🌐
Reddit
reddit.com › r/javascript › how to merge two arrays of objects into a new one
r/javascript on Reddit: How to merge two arrays of objects into a new one
July 26, 2018 -

Hello, I'm currently facing this problem where I have to sorta merge 2 array of objects, in one of my arrays I have a count of messages sent while in the other I have visits to a URL, I have to use this 2 properties to perfom some calculations, they both share a common a property which I can use to "link" together.

I need to combine both into one array where each "day" property conincide. This is the structure.

{
    "MessageCount": [
        {
            "day": "07-23-2018",
            "count": 0
        },
        {
            "day": "07-24-2018",
            "count": 12
        }
    ],
    "LinkCount": [
        {
            "day": "07-23-2018",
            "visits": 12
        },
        {
            "day": "07-24-2018",
            "visits": 10
        }
}

I could also work with advice with the query I'm using, maybe I could build the array instead of doing a merge. I'm doing pretty much 2 identical queries to different MongoDB collections to build those arrays.

statistics.smsSentCount = await Promise
    .all(collections.map((collection) =>
      collection.smsSent.collection.count(filters).exec()
      .then((count) => {
        return {
          day: collection.smsSent.day,
          count,
        };
      })));
🌐
Paige Niedringhaus
paigeniedringhaus.com › merge javascript objects in an array with different defined properties
Merge JavaScript Objects in an Array with Different Defined Properties | Paige Niedringhaus
June 6, 2022 - This mergeObject() function is the one that actually does the combining of objects. The A and B objects that this function takes in are the two objects with a common sensorId property, and the res variable will be the newly returned object of their properties (and values) combined.
🌐
Quora
quora.com › How-do-you-match-data-and-combine-two-arrays-of-objects-JavaScript-arrays-development
How to match data and combine two arrays of objects (JavaScript, arrays, development) - Quora
Answer: If you are using javascript ES6 then you can use spread operator to combine two array of objects Example Const user1=[{“name”:”Rakesh”}, {“name”:”Rohan”}] Const user2=[{“name”:”Suraj”}] Const user3=[… user1,… ...
🌐
TutorialsPoint
tutorialspoint.com › how-to-merge-two-arrays-with-objects-in-one-in-javascript
How to merge two arrays with objects in one in JavaScript?
Here, to check the uniqueness of any object we will check for its unique "name" property. ... const arr1 = [ {name:'test', lastname: 'test', gender:'f'}, {name:'test1', lastname: 'test1', gender:'f'}, {name:'test2', lastname: 'test2', gender:'m'} ]; const arr2 = [ {name:'test21', lastname: 'test21', gender:'f'}, {name:'test1', lastname: 'test1', gender:'f'}, {name:'test2', lastname: 'test2', gender:'m'}, {name:'test22', lastname: 'test22', gender:'m'} ]; const mergeUniquely = (arr1 = [], arr2 = []) => { const newArr = arr1.concat(arr2); const map = {}; const res = []; newArr.forEach(el => { if(!map[el['name']]){ res.push(el); map[el['name']] = 1; }; }); return res; }; console.log(mergeUniquely(arr1, arr2));
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › object › merge objects
Merge two or more JavaScript objects - 30 seconds of code
March 20, 2024 - const deepMerge = (a, b, fn) => [...new Set([...Object.keys(a), ...Object.keys(b)])].reduce( (acc, key) => ({ ...acc, [key]: fn(key, a[key], b[key]) }), {} ); const obj1 = { a: true, b: [1, 2, 3], c: { d: 4, e: 5 }, f: 'foo', }; const obj2 = { a: false, b: [4, 5, 6], c: { d: 6, g: 7 }, f: 'bar', }; const concatFn = (key, a, b) => { if (Array.isArray(a) && Array.isArray(b)) return a.concat(b); if (typeof a === 'object' && typeof b === 'object') return deepMerge(a, b, concatFn); if (typeof a === 'string' && typeof b === 'string') return [a, b].join(' '); return b ?? a; }; deepMerge(obj1, obj2, concatFn); // { // a: false, // b: [ 1, 2, 3, 4, 5, 6 ] // c: { d: 6, e: 5, g: 7 }, // f: 'foo bar' // } ... Master array manipulation in JavaScript with this ES6 article collection. ... Learn how to merge two arrays of objects, while combining objects based on a specified key.
Top answer
1 of 16
137

You can do it like this -

let arr1 = [
    { id: "abdc4051", date: "2017-01-24" },
    { id: "abdc4052", date: "2017-01-22" }
];

let arr2 = [
    { id: "abdc4051", name: "ab" },
    { id: "abdc4052", name: "abc" }
];

let arr3 = arr1.map((item, i) => Object.assign({}, item, arr2[i]));

console.log(arr3);


Use below code if arr1 and arr2 are in a different order:

let arr1 = [
  { id: "abdc4051", date: "2017-01-24" }, 
  { id: "abdc4052", date: "2017-01-22" }
];

let arr2 = [
  { id: "abdc4051", name: "ab" },
  { id: "abdc4052", name: "abc" }
];

let merged = [];

for(let i=0; i<arr1.length; i++) {
  merged.push({
   ...arr1[i], 
   ...(arr2.find((itmInner) => itmInner.id === arr1[i].id))}
  );
}

console.log(merged);

Use this if arr1 and arr2 are in a same order

let arr1 = [
  { id: "abdc4051", date: "2017-01-24" }, 
  { id: "abdc4052", date: "2017-01-22" }
];

let arr2 = [
  { id: "abdc4051", name: "ab" },
  { id: "abdc4052", name: "abc" }
];

let merged = [];

for(let i=0; i<arr1.length; i++) {
  merged.push({
   ...arr1[i], 
   ...arr2[i]
  });
}

console.log(merged);

2 of 16
81

This solution is applicable even when the merged arrays have different sizes. Also, even if the matching keys have different names.

Merge the two arrays by using a Map as follows:

const arr1 = [
  { id: "abdc4051", date: "2017-01-24" }, 
  { id: "abdc4052", date: "2017-01-22" },
  { id: "abdc4053", date: "2017-01-22" }
];
const arr2 = [
  { nameId: "abdc4051", name: "ab" },
  { nameId: "abdc4052", name: "abc" }
];

const map = new Map();
arr1.forEach(item => map.set(item.id, item));
arr2.forEach(item => map.set(item.nameId, {...map.get(item.nameId), ...item}));
const mergedArr = Array.from(map.values());

console.log(JSON.stringify(mergedArr));
.as-console-wrapper { max-height: 100% !important; top: 0; }

Run the stack snippet to see the result:

[
  {
    "id": "abdc4051",
    "date": "2017-01-24",
    "nameId": "abdc4051",
    "name": "ab"
  },
  {
    "id": "abdc4052",
    "date": "2017-01-22",
    "nameId": "abdc4052",
    "name": "abc"
  },
  {
    "id": "abdc4053",
    "date": "2017-01-22"
  }
]
🌐
Envato Tuts+
code.tutsplus.com › home › coding fundamentals
Merge Arrays in JavaScript: With and Without Duplicates | Envato Tuts+
February 19, 2023 - The spread operator [...] syntax allows two or more arrays to be adjoined. This will create a new array, without modifying the parent arrays. This method does not remove duplicates. Instead, all the array elements in the merged array will be inserted in the same order as the source. Here is an example to help you understand: The Spread operator makes use of [Symbol.iterator], which is a property of the object...
🌐
SamanthaMing
samanthaming.com › tidbits › 49-2-ways-to-merge-arrays
2 Ways to Merge Arrays in JavaScript | SamanthaMing.com
Here are 2 ways to combine your arrays and return a NEW array. Here are 2 ways to combine your arrays and return a NEW array. Let's look at how we do that using spread and concat.
🌐
Go Make Things
gomakethings.com › how-to-deep-merge-arrays-and-objects-with-javascript
How to deep merge arrays and objects with JavaScript | Go Make Things
// Loop through each item for (let obj of objs) { // ... // Otherwise, merge if (type === 'array') { clone = [...clone, ...structuredClone(obj)]; } else if (type === 'object') { mergeObj(clone, obj); } } Inside the mergeObj() function, we’ll ...