HomeToolsAbout a20k

concat

What is it

Appends contents of another array to existing array

const array1 = [1, 2, 3] const array2 = ["a", "b", "c"] const resultOfConcat = array1.concat(array2); console.log(resultOfConcat) // [1, 2, 3, "a", "b", "c"]

Alternative

Spread operator is recommended when concatenating 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]
© VincentVanKoh