把数组中某个值删除,并返回新数组,需要遍历旧数组找到要删除的元素
/*
* 删除数组中指定值
*/
Array.prototype.remove=function(value){
var len = this.length;
for(var i=0,n=0;iif(this[i]!=value){
this[n++]=this[i];
}else{
console.log(i);//测试所用
}
}
this.length = n;
};
var arr = ['1','2','3','5','2','1','4','2','2'];
arr.remove(2);
console.log(arr);