combine two arrays javascript
snippet in javascript

combine two arrays javascript

user9381

let arr1 = [0, 1, 2];
let arr2 = [3, 5, 7];
let primes = arr1.concat(arr2);

// > [0, 1, 2, 3, 5, 7]

merge array in js

user9855

//for ES5
var array1 = ["Rahul", "Sachin"];
var array2 = ["Sehwag", "Kohli"];

var output = array1.concat(array2);
console.log(output);

//for ES6, we use spread operators to concat arrays

var array1 = ["Dravid", "Tendulkar"];
var array2 = ["Virendra", "Virat"];

var output = [...array1, ...array2];
console.log(output);

join 2 array in javascript

user4843

const array1 = ["Vijendra","Singh"];
const array2 = ["Singh", "Shakya"];
const array3 = [...array1, ...array2];

how to add an array to another array in javascript

user3155


var hege = ["Cecilie", "Lone"];

var stale = ["Emil", "Tobias", "Linus"];

var kai = ["Robin"];

var children = hege.concat(stale, kai); 

javascript concat two arrays

user7020

//ES6
const array3 = [...array1, ...array2];

javascript array merge

user8021


var hege = ["Cecilie", "Lone"];

var stale = ["Emil", "Tobias", "Linus"];

var children = hege.concat(stale);