الطريقة 1: كرر البيانات
نسخ رمز رمز على النحو التالي:
<script>
Array.Prototype.distinct = function () {
var a = [] ، b = [] ؛
لـ (var prop in this) {
var d = this [prop] ؛
إذا استمرت (D === A [Prop])
if (b [d]! = 1) {
A.Push (D) ؛
ب [د] = 1 ؛
}
}
إرجاع أ ؛
}
var x = ['a' ، 'b' ، 'c' ، 'd' ، 'b' ، 'a' ، 'e' ، 'a' ، 'b' ، 'c' ، 'd' ، "ب ،" ب ، "ب" ، "أ" ، "هـ"] ؛
document.write ('Array Original:'+x) ؛
document.write ("<br />") ؛
document.write (بعد التكرار: '+x.distinct ()) ؛
</script>
الطريقة الثانية: خذ بيانات مكررة
نسخ رمز رمز على النحو التالي:
<script type = "text/javaScript">
Array.Prototype.distinct = function () {
var a = [] ، b = [] ، c = [] ، d = [] ؛
لـ (var prop in this) {
var d = this [prop] ؛
إذا (d === a [prop])
{{
يكمل؛
} // منع الدورة الدموية
if (b [d]! = 1) {
A.Push (D) ؛
ب [د] = 1 ؛
}
آخر {
C.Push (D) ؛
d [d] = 1 ؛
}
}
// إرجاع أ ؛
العودة c.distinct1 () ؛
}
Array.Prototype.distint1 = function () {
var a = [] ، b = [] ؛
لـ (var prop in this) {
var d = this [prop] ؛
إذا استمرت (D === A [Prop])
if (b [d]! = 1) {
A.Push (D) ؛
ب [د] = 1 ؛
}
}
إرجاع أ ؛
}
var x = ['a' ، 'b' ، 'c' ، 'd' ، 'b' ، 'a' ، 'e' ، 'a' ، 'b' ، 'c' ، 'd' ، "b ، 'b ،' b 'a' a '،' e '،' f '،' f '،' g '] ؛
document.write ('Array Original:'+x) ؛
document.write ("<br />") ؛
document.write (بعد التكرار: '+x.distinct ()) ؛
</script>