js把一個數組插入到另外一個數組的指定位置

var arr1 = ['a', 'b', 'c']; 
var arr2 = ['1', '2', '3']; 
// 把arr2 變成一個適合splice的數組(包含splice前2個參數的數組)
arr2.unshift(2, 0); 
console.log(arr2); 
//[2, 0, "1", "2", "3"]
Array.prototype.splice.apply(arr1, arr2); 
console.log(arr1); 
//["a", "b", "1", "2", "3", "c"]
相關文章
相關標籤/搜索