Advertisement
728x90
The concat() method is used to join two or more arrays by returning a new array containing all the elements. The syntax would be as below,
javascript
1array1.concat(array2, array3, ..., arrayX)Let's take an example of array's concatenation with veggies and fruits arrays,
javascript
1var veggies = ["Tomato", "Carrot", "Cabbage"];
2
3var fruits = ["Apple", "Orange", "Pears"];
4
5var veggiesAndFruits = veggies.concat(fruits);
6
7console.log(veggiesAndFruits); // Tomato, Carrot, Cabbage, Apple, Orange, PearsAdvertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 2
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
345of476