js数组中判断是否有重复值
方法一
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]);
}
}
方法二
var array = ['1','2','3','4','3']
var str = array.join(",")+",";
alert(s);
for(var i=0;i<array.length;i++) {
if(str.replace(array[i]+",","").indexOf(array[i]+",")>-1) {
alert("数组中有重复元素:" + array[i]);
break;
}
}
方法三
var arr = ['1','2','3','4','3']
function isRepeat(arr){
var hash = {};
for(var i in arr) {
if(hash[arr[i]]) {
return true;
}
hash[arr[i]] = true;
}
return false;
}