English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
concat()The method is used to merge two or more arrays.
This method does not change the existing array but returns a new array.
array.concat(array1, array2, ..., arrayZ)
var fruits = ["Apple", "Mango", "Banana"]; var numbers = [5, 10, 12, 98, 3]; var arr = fruits.concat(numbers);Test and See‹/›
The numbers in the table specify the first browser version that fully supports the concat() method:
Method | |||||
concat() | 1 | 1 | Is | Is | 5.5 |
Parameter | Description |
---|---|
array1, array2, ..., arrayZ | The arrays to be merged |
Return Value: | A new Array example |
---|---|
JavaScript Version: | ECMAScript 1 |
The following code concatenates three arrays:
var num1 = [1, 2, 3]; var num2 = [4, 5, 6]; var num3 = [7, 8, 9]; var nums = num1.concat(num2, num3);Test and See‹/›
The following code adds three values to an array:
var alpha = ['a', 'b', 'c' var alphaNumeric = alpha.concat(1, 2, [3, 4, 5]);Test and See‹/›