数组中的对象,判断是否有重复值、

蛋疼,销售中有重复商品上报

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