.concat()

Published Jun 5, 2021Updated Oct 6, 2021
Contribute to Docs

The .concat() array method merges, or concatenates, two or more arrays.

Syntax

The .concat() method does not change the existing arrays, but instead returns a new array.

array1.concat(array2);

It can also concatenate more than two arrays:

array1.concat(array2, array3, array4);

Example 1

Concatenating two arrays:

const grocery1 = ['blueberries', 'eggs', 'artichoke'];
const grocery2 = ['milk', 'cookies'];
const grocery = grocery1.concat(grocery2);
console.log(grocery);
// Output: [ 'blueberries', 'eggs', 'artichoke', 'milk', 'cookies' ]

Example 2

const balls1 = ['⚽', '🏈', '⚾', '🎾'];
const balls2 = ['🏀', '🏐'];
const balls = balls1.concat(balls2);
console.log(balls);
// Output: [ '⚽', '🏈', '⚾', '🎾', '🏀', '🏐' ]

Codebyte Example

Concatenating three arrays:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn JavaScript on Codecademy