.concat()

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:

Code
Output
Loading...

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn JavaScript on Codecademy