.concat()
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:
Contribute to Docs
- 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.
Learn JavaScript on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours