There are many methods to determine whether there are repeated values in the array. This article recommends three practical methods for you. If you are interested, refer to the following. I hope to help you with Method 1:
The Code is as follows:
Var ary = new Array ("111", "22", "33", "111 ");
Var s = ary. join (",") + ",";
For (var I = 0; I
If (s. replace (ary [I] + ",", ""). indexOf (ary [I] + ",")>-1 ){
Alert ("repeated elements in the array:" + ary [I]);
Break; Foreign Language House
}
}
Method 2:
The Code is as follows:
Var ary = new Array ("111", "22", "33", "111 ");
Var nary = ary. sort ();
For (var I = 0; I
If (nary [I] = nary [I + 1]) {
Alert ("repeated array content:" + nary [I]);
}
}
Method 3: Inland Transportation
The Code is as follows:
Function isRepeat (arr ){
Var hash = {};
For (var I in arr ){
If (hash [arr [I])
Return true;
Hash [arr [I] = true;
}
Return false;
}