æ¹æ³ä¸ï¼
var ary = new Array("111","22","33","111");
var s = ary.join(",")+",";
for(var i=0;i<ary.length;i++) {
if(s.replace(ary[i]+",","").indexOf(ary[i]+",")>-1) {
alert("æ°ç»ä¸æéå¤å
ç´ ï¼" + ary[i]);
break;å¤è¯å±
}
}
æ¹æ³äºï¼
var ary = new Array("111","22","33","111");
var nary=ary.sort();
for(var i=0;i<ary.length;i++){
if (nary[i]==nary[i+1]){
alert("æ°ç»éå¤å
容ï¼"+nary[i]);
}
}
æ¹æ³ä¸ï¼
function isRepeat(arr){
var hash = {};
for(var i in arr) {
if(hash[arr[i]])
return true;
hash[arr[i]] = true;
}
return false;
}
温馨提示:内容为网友见解,仅供参考