JavaScript concat () method
Examples
The combined value of the three arrays:
var hege = ["Cecilie", "Lone"];
var stale = ["Emil", "Tobias", "Linus"];
var kai = ["Robin"];
var children = hege.concat(stale,kai);
var stale = ["Emil", "Tobias", "Linus"];
var kai = ["Robin"];
var children = hege.concat(stale,kai);
children output:
Cecilie,Lone,Emil,Tobias,Linus,Robin
try it"
Definition and Usage
concat () method is used to connect two or more arrays.
This method does not change the existing array, but only returns a copy of the array is connected.
Browser Support
All major browsers support concat () property.
grammar
array1.concat( array2 , array3 ,..., arrayX )
Parameter Values
参数 | 描述 |
---|---|
array2 , array3 , ..., arrayX | 必需。该参数可以是具体的值,也可以是数组对象。可以是任意多个。 |
return value
Type | 描述 |
---|---|
Array 对象 | 返回一个新的数组。该数组是通过把所有 arrayX 参数添加到 arrayObject 中生成的。如果要进行 concat() 操作的参数是数组,那么添加的是数组中的元素,而不是数组。 |
technical details
JavaScript version: | 1.2 |
---|