如何判断JavaScript 数组含有重复值

2024-12-26 12:38:23
推荐回答(1个)
回答1:

var ary = new Array("aaa","cc","dd","aaa");
var s = ary.join(",")+",";
for(var i=0;i if(s.replace(ary[i]+",","").indexOf(ary[i]+",")>-1) {
alert("数组中有重复元素:" + ary[i]);
break;
}
}