如题所述
æ¹æ³ä¸:
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;
}
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;
}
温馨提示:答案为网友推荐,仅供参考