组合两个或两个以上的数组。
## 语法
~~~
array1.concat([item1[, item2[, . . . [, itemN]]]])
~~~
## 参数
|参数|定义|
|--|--|
|array1|必需。其他数组连接到的 Array 对象。|
|item1,. . ., itemN|可选。要添加到 array1 的末尾的附加项。|
## 备注
concat 方法返回一个 Array 对象,它包含 array1 和任何其他提供的项的连接。
要添加的项 (item1 itemN) 会按顺序(从列表中的第一个项开始)添加到数组。如果某一项为数组,则其内容将添加到 array1 的末尾。如果该项不是数组,则将其作为单个数组元素添加到数组末尾。
源数组元素按以下规则复制到结果数组:
- 如果从连接到新数组的任何数组中复制某个对象,则该对象引用仍然指向相同的对象。不论新数组和原始数组中哪一个有改变,都将引起对方的改变。
- 如果将某个数字或字符串值添加到新数组,则只复制其值。更改一个数组中的值不会影响另一个数组中的值。
下面的示例演示如何将 concat 方法用于数组:
~~~
var a, b, c, d;
a = new Array(1,2,3);
b = "dog";
c = new Array(42, "cat");
d = a.concat(b, c);
document.write(d);
//Output:
1, 2, 3, "dog", 42, "cat"
~~~
- ActiveXObject对象
- Array对象
- constructor属性
- length属性
- prototype属性
- Array.from函数
- Array.isArray函数
- Array.of函数
- concat方法
- entries方法
- every方法
- fill方法
- filter方法
- findIndex方法
- forEach方法
- indexOf方法
- join方法
- keys方法
- lastIndexOf方法
- map方法
- pop方法
- push方法
- reduce方法
- reduceRight方法
- reverse方法
- shift方法
- slice方法
- some方法
- sort方法
- splice方法
- toString方法
- unshift方法
- valueOf方法
- values方法
- ArrayBuffer对象
- byteLength属性
- ArrayBuffer.isView函数
- slice方法
- arguments对象
- 0...n 属性(参数)
- callee 属性(参数)
- length 属性 (arguments)
- Boolean对象
- constructor 属性(布尔值)
- prototype 属性(布尔值)
- toString 方法 (Boolean)
- valueOf 方法 (Boolean)
- DataView对象
- buffer属性 (DataView)
- byteLength属性(DataView)
- byteOffset属性(DataView)
- getInt8方法(DataView)
- getUint8方法(DataView)
- getInt16方法(DataView)
- getUint16方法(DataView)
- getInt32方法(DataView)
- getUint32方法(DataView)
- getFloat32方法(DataView)
- getFloat64方法(DataView)
- setInt8方法(DataView)
- setUint8方法(DataView)
- setInt16方法(DataView)
- setUint16方法(DataView)
- setInt32方法(DataView)
- setUint32方法(DataView)
- setFloat32方法(DataView)
- setFloat64方法(DataView)
- Date对象
- Debug对象
- Enumerator对象
- Error对象
- Float32Array对象
- Float64Array对象
- Function对象
- Global对象
- Int8Array对象
- Int16Array对象
- Int32Array对象
- Intl.Collator对象
- Intl.DateTimeFormat对象
- Intl.NumberFormat对象
- JSON对象
- Map对象
- Math对象
- Number对象
- Object对象
- Promise对象
- 代理对象
- Reflect对象
- RegExp对象
- 正则表达式对象
- Set对象
- String对象
- 符号对象
- Uint8Array对象
- Uint8ClampedArray对象
- Uint16Array对象
- Uint32Array对象
- VBArray对象
- WeakMap对象
- WeakSet对象
- WinRTError对象