Easy Tutorial
❮ Prop Element Children Prop Datetime Local Readonly ❯

JavaScript concat() Method

JavaScript Array Object

Example

Merge the values of three arrays:

var a = ["Google", "Taobao"];
var b = ["tutorialpro", "Wiki", "Zhihu"];
var c = a.concat(b);
document.write(c);

children Output result:

Google,Taobao,tutorialpro,Wiki,Zhihu

Definition and Usage

The concat() method is used to join two or more arrays.

This method does not change the existing arrays but instead returns a new array.


Browser Support

All major browsers support the concat() method.


Syntax

array1.concat(array2, array3, ..., arrayX)

Parameters

Parameter Description
array2, array3, ..., arrayX Required. The arrays to be concatenated.

Return Value

Type Description
Array object Returns a new array. This array is formed by adding all arrayX parameters to arrayObject. If the parameters for concat() are arrays, the elements of the arrays are added, not the arrays themselves.

Technical Details

| JavaScript Version: | 1.2 | | --- | --- |


More Examples

The following example uses the concat() method to add the elements of array2 to the end of array1 and returns a new array containing all elements of array1 and array2.

Example

Merge two arrays:

const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);

console.log(array3);  // Output: ['a', 'b', 'c', 'd', 'e', 'f']

children Output result:

['a', 'b', 'c', 'd', 'e', 'f']

The following example uses the concat() method to add the elements of array2 and array3 to the end of array1 and returns a new array.

Example

Merge three arrays:

const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = ['g', 'h', 'i'];
const array4 = array1.concat(array2, array3);

console.log(array4);  // Output: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']

children Output result:

['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']

JavaScript Array Object

❮ Prop Element Children Prop Datetime Local Readonly ❯