方法1:データを繰り返します
次のようにコードコードをコピーします。
<スクリプト>
array.prototype.distinct = function(){
var a = []、b = [];
for(これでvar prop){
var d = this [prop];
if(d === a [prop])継続します
if(b [d]!= 1){
a.push(d);
b [d] = 1;
}
}
aを返します。
}
var x = ['a'、 'b'、 'c'、 'd'、 'b'、 'a'、 'e'、 'a'、 'b'、 'c'、 'd'、 'B、' b、 'b'、 'a'、 'e'];
document.write( '元の配列:'+x);
document.write( "<br />");
document.write(繰り返し後: '+x.distinct());
</script>
方法2:複製データを取得します
次のようにコードコードをコピーします。
<script type = "text/javascript">
array.prototype.distinct = function(){
var a = []、b = []、c = []、d = [];
for(これでvar prop){
var d = this [prop];
if(d === a [prop])
{{
続く;
} //プロポタイプへの循環を防ぎます
if(b [d]!= 1){
a.push(d);
b [d] = 1;
}
それ以外 {
c.push(d);
d [d] = 1;
}
}
// aを返します;
c.distinct1()を返します。
}
array.prototype.distint1 = function(){
var a = []、b = [];
for(これでvar prop){
var d = this [prop];
if(d === a [prop])継続します
if(b [d]!= 1){
a.push(d);
b [d] = 1;
}
}
aを返します。
}
var x = ['a'、 'b'、 'c'、 'd'、 'b'、 'a'、 'e'、 'a'、 'b'、 'c'、 'd'、 'B、' b、 'b' a 'a'、 'e'、 'f'、 'f'、 'g'];
document.write( '元の配列:'+x);
document.write( "<br />");
document.write(繰り返し後: '+x.distinct());
</script>