Heim > Web-Frontend > js-Tutorial > 本地对象Array的原型扩展实现代码_javascript技巧

本地对象Array的原型扩展实现代码_javascript技巧

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-05-16 18:14:41
Original
966 Leute haben es durchsucht
复制代码 代码如下:

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());

果果的去重方法
复制代码 代码如下:

Array.prototype.del=function(){
return (function (i, n, j, u, o){
for (; 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())
Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
Array zu Array
Aus 1970-01-01 08:00:00
0
0
0
PHP-Array
Aus 1970-01-01 08:00:00
0
0
0
Array
Aus 1970-01-01 08:00:00
0
0
0
PHP-Array-Transformation
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage