js 判断数组对象中的某个属性是否存在相等的

Posted on 2021-04-13 15:47  zkx4213  阅读(3672)  评论(0编辑  收藏  举报

var ary = [];
var obj = {}
obj.kpiName = "1";
obj.kpiWeight = "1";
obj.kpiDesc = "1";
ary.push(obj);

var obj1 = {}
obj1.kpiName = "3";
obj1.kpiWeight = "2";
obj1.kpiDesc = "2";
ary.push(obj1);

console.log(isRepeat(ary))

// 判断kpiName是否存在重复的

function isRepeat(arr) {
var hash = {};
for(var i in arr) {
debugger;
if(hash[arr[i].kpiName]) {
return true;
}
hash[arr[i].kpiName] = true;
}
return false;
}

Copyright © 2024 zkx4213
Powered by .NET 9.0 on Kubernetes