js add array to another array code example
Example 1: javascript append to array
var colors=["red","white"];
colors.push("blue");
Example 2: merge array in js
var array1 = ["Rahul", "Sachin"];
var array2 = ["Sehwag", "Kohli"];
var output = array1.concat(array2);
console.log(output);
var array1 = ["Dravid", "Tendulkar"];
var array2 = ["Virendra", "Virat"];
var output = [...array1, ...array2];
console.log(output);
Example 3: assign array to another array javascript
var ar = ["apple","banana","canaple"];
var bar = Array.from(ar);
alert(bar[1]);
Example 4: javascript push all elements of array to another array
var arrayA = [1, 2];
var arrayB = [3, 4];
var newArray = arrayA.concat(arrayB);
Example 5: concat js mdn
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);
console.log(array3);
Example 6: js combine two arrays
const letters = ['a', 'b', 'c'];
const numbers = [1, 2, 3];
letters.concat(numbers);