我们先来看看具体的场景:
var q = [ 5, 5, 1, 9, 9, 6, 4, 5, 8];
var b = [ "tie", "mao", "csdn", "ren", "fu", "fei"...];
很明显,数组 q 和 b 简单拼接的结果是:
[
5, 5, 1, 9, 9, 6, 4, 5, 8,
"tie", "mao", "csdn", "ren", "fu", "fei"
]
concat...(..)方法
最常见的用法如下:
var c = q.concat( b );q; // [5,5,1,9,9,6,4,5,8]
b; // ["tie","mao","csdn","ren","fu"...,"fei"];c; // [5,5,1,9,9,6,4,5,8,"tie","mao","csdn","ren","fu","fei"]
如您所见, c 是一个全新的数组, 表示 q 和 b 这两个数组的组合...将数组 `b` 插入 `q`
for (var i=0; i < b.length; i++) {
q.push( b[i] );
}q; // [5,5,1,9,9,6,4,5,8,"tie","mao