To delete a value in the array and return a new array, you need to traverse the old array to find the element to be deleted
/*
* Delete the specified value in the array
*/
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);//used for testing
}
}
this.length = n;
};
var arr = ['1','2','3','5','2','1','4','2','2'];
arr.remove(2);
console.log(arr);