ScanSkill

concat

The concat() method is used to concatenate two arrays together.

Syntax

array1.concat(array2)

The concat() method attaches to the right side of an array with the . operator. It takes in an array as a parameter. The concat() method returns an array which is joined form of array that the concat() method is attracted to and the array given as a parameter.

Example

const array1 = [1, 2, 3];
const array2 = [4, 5, 6];

const concatArray = array1.concat(array2);

console.log(concatArray); // Prints: [ 1, 2, 3, 4, 5, 6 ]

We can see that the concat() connects two arrays and returns them, the array to which it is connected having its items at the first.