var arr = [1,2,3,4,5]; var hd = arr.splice(0,3); console.log(hd);
[ 1, 2, 3 ] console.log(arr);
[ 4, 5 ]
var arr = [1,2,3,4,5]; var hd = arr.splice(0,3,"ss","aa"); console.log(hd);
[ 1, 2, 3 ] console.log(arr);
[ "ss", "aa", 4, 5 ]
----
替换
var arr = [1,2,3,4,5];
var hd = arr.splice(1,1,"tt");
console.log(hd);
[ 2 ]
console.log(arr);
[ 1, "tt", 3, 4, 5 ]
---
增加
var arr = [1,2,3,4,5];
var hd = arr.splice(1,0,"aa","dd");
console.log(hd);
[]
console.log(arr);
[ 1, "aa", "dd", 2, 3, 4, 5 ]