방법 1 : 반복 데이터
다음과 같이 코드 코드를 복사하십시오.
<cript>
Array.prototype.distinct = function () {
var a = [], b = [];
for (var prop in this) {
var d =이 [prop];
(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', 'd', 'b,'b, 'b', 'a', 'e'];
document.write ( '원본 배열 :'+x);
document.write ( "<br />");
document.write (반복 후 : '+x.distinct ());
</스크립트>
방법 2 : 중복 데이터를 가져옵니다
다음과 같이 코드 코드를 복사하십시오.
<script type = "text/javaScript">
Array.prototype.distinct = function () {
var a = [], b = [], c = [], d = [];
for (var prop in this) {
var d =이 [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 in this) {
var d =이 [prop];
(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', 'd', 'b,'b, 'b'a 'a', 'e', 'f', 'f', 'g'];
document.write ( '원본 배열 :'+x);
document.write ( "<br />");
document.write (반복 후 : '+x.distinct ());
</스크립트>