JavaScript Array concat()
Examples
Join two arrays:
const arr1 = ["Cecilie", "Lone"];
const arr2 = ["Emil", "Tobias", "Linus"];
const children = arr1.concat(arr2);
Join three arrays:
const arr1 = ["Cecilie", "Lone"];
const arr2 = ["Emil", "Tobias", "Linus"];
const arr3 = ["Robin"];
const children = arr1.concat(arr2, arr3);
Try it Yourself »
More examples below.
Description
The concat()
method concatenates (joins) two or more arrays.
The concat()
method returns a new array, containing the joined arrays.
The concat()
method does not change the existing arrays.
Syntax
array1.concat(array2, array3, ..., arrayX)
Parameters
Parameter | Description |
array1,... | Required. The array(s) to be concatenated. |
Return Value
Type | Description |
Array | The content from the joined arrays. |
More Examples
Concatenate strings and numbers:
const arr1 = ["Cecilie", "Lone"];
const arr2 = [1, 2, 3];
const arr3 = arr1.concat(arr2);
Concatenate nested arrays:
const arr1 = [1, 2, [3, 4]];
const arr2 = [[5, 6], 7, 8];
const arr3 = arr1.concat(arr2);
Try it Yourself »
Array Tutorials:
Browser Support
concat()
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |