数组中的对象,判断是否有重复值转载
原创var arry = [{
itemType: "1",
item_id: "86753",
organizationId: "3117",
price: "1000",
qty: "1",
},
{
itemType: "1",
item_id: "86753",
organizationId: "3118",
price: "1000",
qty: "1",
},
{
itemType: "1",
item_id: "86753",
organizationId: "3117",
price: "1000",
qty: "1",
}];
function isRepeat(arr){
var hash = {};
for(var i in arr) {
if(
hash[arr[i].price] &&
hash[arr[i].itemType] &&
hash[arr[i].item_id] &&
hash[arr[i].qty] &&
hash[arr[i].organizationId]
) {
console.log(---, hash[arr[i].price]);
return true;
// hash[arr[i].itemType] = true;
} else {
hash[arr[i].price] = true;
hash[arr[i].itemType] = true;
hash[arr[i].item_id] = true;
hash[arr[i].qty] = true;
hash[arr[i].organizationId] = true;
}
}
return false;
};
console.log(isRepeat(arry));
本文转载如下: https://www.cnblogs.com/GoodPingGe/p/4899663.html
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除