JavaScript Concatenate Arrays

J

For concatenating two arrays into one we will use concat function.

Say we have array1 and array2 and we want to make a new array by merging these two arrays.

The code is:

var array1 = [1,2,3,4,5];
var array2 = [6,7,8,9,10];

var newArray = array1.concat(array2);

console.log(newArray);  // returns [1,2,3,4,5,6,7,8,9,10]

About the author

Imran Pollob

Learn => Practice => Implement => Repeat

Add comment

Categories

Imran Pollob

Learn => Practice => Implement => Repeat

Get in touch