Posted in Javascript onAugust 16, 2013
方法一:
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; }
JS判断数组中是否有重复值得三种实用方法
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@