色婷婷狠狠18禁久久YY,CHINESE性内射高清国产,国产女人18毛片水真多1,国产AV在线观看

Javascript常見面試題-判斷數(shù)組中是否有重復(fù)元素?

方法一:

代碼如下:

varary=newArray("111","22","33","111");

vars=ary.join(",")+",";

for(vari=0;i<ary.length;i++){

if(s.replace(ary[i]+",","").indexOf(ary[i]+",")>-1){

alert("數(shù)組中有重復(fù)元素:"+ary[i]);

break;

}

}

方法二:

代碼如下:

varary=newArray("111","22","33","111");

varnary=ary.sort();

for(vari=0;i<ary.length;i++){

if(nary[i]==nary[i+1]){

alert("數(shù)組重復(fù)內(nèi)容:"+nary[i]);

}}

方法三:

代碼如下:

functionisRepeat(arr){

varhash={};

for(variinarr){

if(hash[arr[i]])returntrue;

hash[arr[i]]=true;

}

returnfalse;

}