Home >Web Front-end >JS Tutorial >Prototype extension implementation code of local object Array_javascript skills

Prototype extension implementation code of local object Array_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 18:14:41955browse
Copy code The code is as follows:

Array.prototype.del=function(){
var b ={},c,i=0,l=this.length,j;
for(;ic=this.shift();
c in b ? b [c] : b[c]=0;
}
for(j in b){
if(b[j]>0)this.push( j||j);
}
return this;
}
var a=[1,2,2,3,3,3,'a','b','b'];
alert(a .del());

Guoguo’s deduplication method
Copy code The code is as follows:

Array.prototype.del=function(){
return (function (i, n, j, u, o){
for (; i < j; i ) {
o = this[i];
o in u ? 0 : (u[this[n ] = o] = 1)
}
this.length = n;
return this
}).call(this, 0, 0, this.length, {})
}
var a=[1,2,2,3,3,3,'a',' b','b'];
alert(a.del())
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