1、这个方法最好用
var that = this,repeatCustomPropsNameArr = [];
parent.customProps.forEach(j=>{
repeatCustomPropsNameArr.push(j.newName);
})
var nary = repeatCustomPropsNameArr.sort();
for(var i = 0; i < nary.length - 1; i++) {
if(nary[i] == nary[i + 1]) {
//有相同数据
return
}
}
2、第二种方法不通用的,js不太熟练的伙伴慎用,对于var ary = new Array("111","3","33","1") 不可行,会判断说有重复值“3”,
var ary = new Array("111","3","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;
}
}
网友评论