How to Merge/Combine Arrays using JavaScript? Last Updated : 07 Nov, 2024 Comments Improve Suggest changes Like Article Like Report Given two or more arrays, the task is to merge (or combine) arrays to make a single array in JavaScript. The simplest method to merge two or more arrays is by using array.concat() method.Using Array concat() MethodThe contact() method concatenates (joins) two or more arrays. It creates a new array after combining the existing arrays.SyntaxmergedArray = array1.concat( array2 ); JavaScript const array1 = [1, 2, 3]; const array2 = [4, 5, 6]; const mergedArray = array1.concat( array2 ); console.log(mergedArray); Output[ 1, 2, 3, 4, 5, 6 ] Please Read JavaScript Array Tutorial for complete understanding of JavaScript Array.Table of ContentUsing Spread OperatorUsing Array push() Method with Spread OperatorUsing for LoopUsing Spread OperatorThe spread operator is a concise way to merge two or more arrays. The spread operator expand the elements of one or more arrays into a new array. It is introduced in ES6.SyntaxmergedArray = [ ...array1, ...array2 ]; JavaScript const array1 = [1, 2, 3]; const array2 = [4, 5, 6]; const mergedArray = [...array1, ...array2]; console.log(mergedArray); Output[ 1, 2, 3, 4, 5, 6 ] Using Array push() Method with Spread OperatorThe array push() method adds one or more elements to the end of an array and returns the new length of the array. To add one or more array using push() method, we can use Spread Operator.SyntaxmergedArray = array1.push( ...array2 ); JavaScript const array1 = [1, 2, 3]; const array2 = [4, 5, 6]; array1.push(...array2); console.log(array1); Output[ 1, 2, 3, 4, 5, 6 ] Using for LoopThe for loop can also be used to merge arrays manually by iterating through each element and pushing them into a new array. JavaScript const array1 = [1, 2, 3]; const array2 = [4, 5, 6]; const mergedArray = []; for (let i = 0; i < array1.length; i++) { mergedArray.push(array1[i]); } for (let i = 0; i < array2.length; i++) { mergedArray.push(array2[i]); } console.log(mergedArray); Output[ 1, 2, 3, 4, 5, 6 ] Comment More infoAdvertise with us Next Article How to Merge/Combine Arrays using JavaScript? P prerak_jain Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Misc JavaScript-Questions Similar Reads Merge K Sorted Array using JavaScript We are given K sorted arrays and our task is to merge them into a single sorted array in JavaScript.Example:Input: arrays = [[2, 4, 5], [1, 3, 8], [0, 7, 9]];Output: [0, 1, 2, 3, 4, 5, 7, 8]These are the following approaches:Table of ContentNaive ApproachDivide and Conquer ApproachMin-Heap ApproachN 5 min read How to cartesian product of 2 arrays using JavaScript ? The task is to compute the cartesian product of two JavaScript arrays with the help of JavaScript. Here are a few techniques discussed. Approach 1: Create a new array.Traverse the first array by the outer loop and the second array by the inner loop.In the inner loop, Concatenate the first array elem 2 min read How to Create Zip Array in JavaScript ? Working with arrays in JavaScript often requires merging or combining multiple arrays into a single structure. One common operation in array manipulation is known as "zipping," where corresponding elements from multiple arrays are paired together to create a new array. Example:Input: let a = [1, 2, 3 min read Convert Array to String in JavaScript In JavaScript, converting an array to a string involves combining its elements into a single text output, often separated by a specified delimiter. This is useful for displaying array contents in a readable format or when storing data as a single string. The process can be customized to use differen 7 min read JavaScript Array concat() Method The concat() method concatenates (joins) two or more arrays. It returns a new array, containing the joined arrays. This method is useful for combining arrays without modifying the originals.Syntax:let newArray1 = oldArray.concat()let newArray2 = oldArray.concat(value0)let newArray3 = oldArray.concat 3 min read Like