concat
Appends contents of another array to existing array.
const array1 = [1, 2, 3]; const array2 = ["a", "b", "c"]; const resultOfConcat = array1.concat(array2); // [1, 2, 3, "a", "b", "c"] const greetList = ["Hello", " ", "Venkat", "!"]; "".concat(...greetList); // "Hello Venkat!" // other behaviors "".concat({}); // "[object Object]" "".concat([]); // "" "".concat(null); // "null" "".concat(true); // "true" "".concat(4, 5); // "45"
Spread operator
is recommended when concatenating/merging multiple arrays.
const arr1 = [0,1,2]; const arr2 = [3,4,5]; const arr3 = [...arr1, ...arr2]; console.log(arr3); // [0,1,2,3,4,5]