combine elements from array javascript code example
Example 1: js combine arrays
const array1 = ["Vijendra","Singh"];
const array2 = ["Singh", "Shakya"];
const array3 = [...array1, ...array2];
Example 2: javascript merge array
// ES5 version use Array.concat:
let array1 = ["a", "b"]
let array2 = ["1", "2"]
let combinedArray = array1.concat(array2);
// combinedArray == ["a", "b", "1", "2"]
// ES6 version use destructuring:
let array1 = ["a", "b"]
let array2 = ["1", "2"]
let combinedArray = [...array1, ...array2]
// combinedArray == ["a", "b", "1", "2"]