.concat()
Anonymous contributor
Anonymous contributor3077 total contributions
Anonymous contributor
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:
All contributors
- Anonymous contributorAnonymous contributor3077 total contributions
- Christine_Yang271 total contributions
- christian.dinh2481 total contributions
- Anonymous contributor
- Christine_Yang
- christian.dinh
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.