1:在数组指定位置插入元素
array.splice(2, 0, "three"); //在索引2的位置,删除0个元素后,插入元素“three”
例子:
// 原来的数组
var array = ["one", "two", "four"];
// splice(position, numberOfItemsToRemove, item)
// 拼接函数(索引位置, 要删除元素的数量, 元素)
array.splice(2, 0, "three");
0array; // 现在数组是这个样子 ["one", "two", "three", "four"]
2:join
输入:
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.join())
输出:
George,John,Thomas
3:concat
var q = [ 5, 5, 1, 9, 9, 6, 4, 5, 8];
var b = [ "tie", "mao", "csdn", "ren", "fu", "fei" ];
//使用方法:
var c = q.concat( b );
//拼接结果:
[
5, 5, 1, 9, 9, 6, 4, 5, 8,
"tie", "mao", "csdn", "ren", "fu", "fei"
]