把数组中某个值删除,并返回新数组,需要遍历旧数组找到要删除的元素
[javascript]
view plain
copy
Array.prototype.remove=function(value){ var len = this.length; for(var i=0,n=0;i<len;i++){ if(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);