Array.prototype.remove=function(from,to){
var rest=this.slice((to||from)+1||this.length);
this.length=from<0?this.length+from:from;
return this.push.apply(this,rest);
}
第二行代码的slice参数不是很理解,有没有人指导下啊,拜服了呵呵!!!!
var rest=this.slice((to||from)+1||this.length);
this.length=from<0?this.length+from:from;
return this.push.apply(this,rest);
}
第二行代码的slice参数不是很理解,有没有人指导下啊,拜服了呵呵!!!!
比如
var arr = [1,2,3,4,5];
var cc = arr.slice(1,3);//cc就是[2,3]
var dd = arr.slice(1);//dd就是[2,3,4,5]
和slice对应的方法是splice
他俩的区别是slice操作完原数组后不改变原数组 而splice直接就更改了原数组