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.
🌐
W3Schools
w3schools.com › jsref › jsref_concat_array.asp
JavaScript Array concat() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › join
Array.prototype.join() - JavaScript | MDN
If the array has only one item, then that item will be returned without using the separator. const elements = ["Fire", "Air", "Water"]; console.log(elements.join()); // Expected output: "Fire,Air,Water" console.log(elements.join("")); // Expected output: "FireAirWater" console.log(elements.join("-")); // Expected output: "Fire-Air-Water" ... A string to separate each pair of adjacent elements of the array.
🌐
TechOnTheNet
techonthenet.com › js › array_concat.php
JavaScript: Array concat() method
In JavaScript, concat() is an Array method that is used to concatenate two or more arrays into a new array. Because the concat() method is a method of the Array object, it must be invoked through a particular instance of the Array class.
🌐
W3Resource
w3resource.com › javascript › object-property-method › array-concat.php
JavaScript concat() Method : Array Object - w3resource
var array1=new Array(2); array1[0] = "Fruits"; array1[1] = "Color"; var array2=new Array(2); array2[0] = "Orange"; array2[1] = "Apple"; var array3=new Array(2); array3[0] = "Banana"; array3[1] = "Cherry"; var joinarray=array1.concat(array2,array3); var newParagraph = document.createElement("p"); var newText = document.createTextNode(joinarray); newParagraph.appendChild(newText); document.body.appendChild(newParagraph); ... JavaScript Core objects, methods, properties.
🌐
Go Make Things
gomakethings.com › merging-arrays-and-objects-with-vanilla-javascript
Merging arrays and objects with vanilla JavaScript | Go Make Things
Today, we’re going to talk about how to merge multiple arrays or objects together. Let’s dig in! You can use the Array.prototype.concat() method to merge two or more arrays together.
🌐
DEV Community
dev.to › smlka › fun-with-arrayprototypeconcat-554l
Merge array-like objects by Array.prototype.concat() - DEV Community
June 27, 2024 - Let's dive into the Array.prototype.concat() method in JavaScript. This handy method helps you merge arrays, creating a new array with elements from the arrays you provide. Here's a quick example: const arr0= [], arr1 = [1,2], arr2 = [3,4]; ...
Find elsewhere
🌐
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.
🌐
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 - There are more than a couple of ways to merge two or more arrays into one in JavaScript. Using the spread operator or the concat() method is the most optimal solution.
🌐
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. I like using the Spread operator. But if you need older browser support, you should use Concat.
🌐
Medium
arek-jaworski.medium.com › how-to-join-two-arrays-of-objects-into-one-with-javascript-ab70d467cedd
How to join two arrays of objects into one with JavaScript | by Arek Jaworski | Medium
July 4, 2019 - We can achieve that easily with plain javascript and Array.prototype.concat() method: const result = abc.concat(def); console.log(result); // outputs: ['a', 'b', 'c', 'd', 'e', 'f'] Let’s try the same with array of objects: const a = [{id: ...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-merge-arrays-in-javascript-array-concatenation-in-js
How to Merge Arrays in JavaScript – Array Concatenation in JS
November 28, 2022 - You use the concat method of arrays to combine the contents of an array with new values to form a new array. These new values can be numbers, strings, booleans, objects, or even, arrays.
🌐
Codedamn
codedamn.com › news › javascript
JavaScript concat array explained – How to merge arrays in JS
June 24, 2023 - In conclusion, the concat() method is a powerful tool for merging arrays in JavaScript. This blog post has provided an overview of its usage and alternative methods for merging arrays.
🌐
GeeksforGeeks
geeksforgeeks.org › 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
July 5, 2024 - We will explore various approaches to merging two arrays of objects with unique values. ... The concat() method is used to merge array1 and the filtered values from array2 to create a new array.
🌐
GitHub
gist.github.com › yesvods › 51af798dd1e7058625f4
Merge Arrays in one with ES6 Array spread · GitHub
let arr1 = [1, 2, 3]; let arr2 = [4, 5, 6]; let concatAndDeDuplicate = (...arrs) => [ ...new Set( [].concat(...arrs) ) ]; concatAndDeDuplicate(arr1, arr2, [7, 8, 9, 2, 4]); // [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] And if you have multiple arrays of potentialy identical objects, you can use this :
🌐
Mimo
mimo.org › glossary › javascript › array-concatenation
JavaScript Array Concatenate: Syntax, Usage, and Examples
Merge arrays in JavaScript using concat(), the spread operator (...), or push(). Quickly combine lists, results, or values without loops.
🌐
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,… ...