function isRepeat(arr){ let hash = {}; for(let i in arr) { if(hash[arr[i]]) { return true; } hash[arr[i]] = true; } return false; }
方法一 let s = ary.join(",")+",";for(let i=0;i<ary.length;i++) { if(s.replace(ary[i]+",","").indexOf(ary[i]+",")>-1) { alert("数组中有重复元素:" + ary[i]); break; } } 方法二 let ary = new Array("111","22","33","111"); let nary=ary.slice().sort();for(let i=0;i<ary.length;i++){ if (nary[i]==nary[i+1]){ alert("数组重复内容:"+nary[i]); } }
站长微信:xiaomao0055
站长QQ:14496453