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
๐ŸŒ
Go Make Things
gomakethings.com โ€บ merging-arrays-and-objects-with-vanilla-javascript
Merging arrays and objects with vanilla JavaScript | Go Make Things
January 4, 2023 - Call the concat() method on the first array, and pass each array to merge with it in as arguments. It returns a new array. let wizards1 = ['Gandalf', 'Radagast']; let wizards2 = ['Merlin', 'Ursula']; let allWizards = wizards1.concat(wizards2); ...
๐ŸŒ
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 - No more loops, comparison or rocket science, the merge operation can be written in a single line of code. It is also worth to notice that in case both objects would contain the same key, the value of the last object, โ€œthe one on the right in the line of codeโ€, is the winning value.
๐ŸŒ
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,
        };
      })));
๐ŸŒ
Medium
rapidfork.medium.com โ€บ merge-arrays-or-arrays-of-objects-in-javascript-tyepscript-1f7c4e83a94a
Merge Arrays or Arrays of Objects in JavaScript/TyepScript | by RapidFork Technology | Medium
May 19, 2024 - If you need a deep merge (for nested objects), you can use Lodashโ€™s merge function. ... const arrayOfObjects = [ { a: 1, b: { x: 1, y: 2 } }, { b: { y: 3, z: 4 }, c: 4 }, { d: 5 } ];const mergedObject = _.merge({}, ...arrayOfObjects);console.log(mergedObject); // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 4, d: 5 }
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ concat
Array.prototype.concat() - JavaScript - MDN Web Docs
July 10, 2025 - 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.
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-merge-multiple-array-of-object-by-id-in-javascript
How to Merge Multiple Array of Object by ID in JavaScript? - GeeksforGeeks
August 23, 2024 - [ { id: 1, name: 'HTML', popularity: 'High' }, { id: 2, name: 'CSS', popularity: 'Medium' }, { id: 3, name: 'JavaScript' } ] The reduce method provides a concise and functional way to merge arrays by accumulating results during iteration. In this approach, reduce iterates over each object in the first array, using find to locate a corresponding object in the second array based on the ID. When a match is found, the two objects are merged and added to the accumulator array. After processing all elements, the final merged array is returned, offering a streamlined solution for combining objects from multiple arrays
๐ŸŒ
SitePoint
sitepoint.com โ€บ blog โ€บ javascript โ€บ how to merge objects in javascript
How to Merge Objects in JavaScript โ€” SitePoint
November 5, 2024 - The Spread operator (โ€ฆ) in JavaScript is a modern and efficient way to merge objects. It allows an iterable such as an array expression or string to be expanded in places where zero or more arguments or elements are expected.
๐ŸŒ
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 - Merging two arrays of objects with unique values is a common task in JavaScript. This operation involves combining the elements of two arrays while ensuring that each resulting object has a unique identifier.
๐ŸŒ
Kranthi Lakum
lakum.in โ€บ blog โ€บ merge-array-of-objects-in-javascript
Merge Array of Objects in JavaScript | Kranthi Lakum
If it doesn't exist, it creates a new object with the current object's id as the key. After that, it uses the Object.assign() method to merge the current object with the object in the accumulator object with the same key.
๐ŸŒ
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
April 27, 2023 - This is the object or array that weโ€™ll merge all other items into, so weโ€™ll return it back out. function deepMerge (...objs) { // Create a clone of the first item in the objs array let clone = structuredClone(objs.shift()); return clone; }
๐ŸŒ
30 Seconds of Code
30secondsofcode.org โ€บ home โ€บ javascript โ€บ array โ€บ combine object arrays
Combine 2 JavaScript object arrays based on a key - 30 seconds of code
March 26, 2024 - For each value in the arrays, you can check if the object has the specified key. If it does, you can add it to the accumulator object, combining it with any existing object that has the same key. This will result in a single object for each unique value of the key property.
๐ŸŒ
JavaScript Tutorial
javascripttutorial.net โ€บ home โ€บ javascript merge objects
How to Merge Objects in JavaScript
March 29, 2020 - ES6 introduced the spread operator (...) which can be used to merge two or more objects and create a new one that has properties of the merged objects. The following example uses the spread operator (...) to merge the person and job objects into the employee object: let person = { firstName: 'John', lastName: 'Doe', age: 25, ssn: '123-456-2356' }; let job = { jobTitle: 'JavaScript Developer', location: 'USA' }; let employee = { ...person, ...job }; console.log(employee); Copy
๐ŸŒ
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 - In this article, we will learn five different ways to merge arrays in JavaScript. We will also conclude which is the best way among all and when to use it. If you like to learn from video content as well, this article is also available as a video tutorial here: ๐Ÿ™‚ ... Alright, let's get started. Using the for loop to merge two or more array elements may be the most viable way. Most of us are aware of how to use for-loops in programming.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Merge Properties of Multiple JavaScript Objects | JavaScript Arrays & Objects for Beginners - YouTube
Can we have a new object that will have properties from multiple objects, in JavaScript? This is very important concept in ES6. You gonna see it and use it i...
Published: January 10, 2022
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-merge-objects-into-a-single-object-array-with-javascript
How to merge objects into a single object array with JavaScript?
March 15, 2026 - let objectArray = [ { id: 22, class: 7 }, { name: "Rohan", age: 12 }, { state: "Delhi", country: "India" } ]; // Method 1: Using Object.assign() let merged1 = Object.assign({}, ...objectArray); console.log("Using Object.assign():", merged1); ...