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);
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn