javascript将数组插入到另一个数组中
将数组arr2插入到数组arr1的index位置:
var arr1 = ['a', 'b', 'c']; var arr2 = ['1', '2', '3']; var index = 1; arr2.unshift(index, 0);
Array.prototype.splice.apply(arr1, arr2); console.log(arr1);
显示结果:
["a", "1", "2", "3", "b", "c"]
将数组arr2插入到数组arr1的index位置:
var arr1 = ['a', 'b', 'c']; var arr2 = ['1', '2', '3']; var index = 1; arr2.unshift(index, 0);
Array.prototype.splice.apply(arr1, arr2); console.log(arr1);
显示结果:
["a", "1", "2", "3", "b", "c"]