时间:2021-07-01 10:21:17 帮助过:24人阅读
var lang = ["php","java","javascript"];
//删除
var removed = lang.splice(1,1);
alert(lang); //php,javascript
alert(removed); //java ,返回删除的项
//插入
var insert = lang.splice(0,0,"asp"); //从第0个位置开始插入
alert(insert); //返回空数组
alert(lang); //asp,php,javascript
//替换
var replace = lang.splice(1,1,"c#","ruby"); //删除一项,插入两项
alert(lang); //asp,c#,ruby
alert(replace); //php,返回删除的项