I have an array of objects, where I'd like to merge some objects if certain data matches. Here is the array:
0: {name: "1", qty: "3", measurement: "Tbsp"}
1: {name: "paprika", qty: "2", measurement: "Tbsp"}
2: {name: "onion", qty: "1", measurement: "cup"}
3: {name: "tomatoes", qty: "16", measurement: "oz"}
4: {name: "tomatoes", qty: "16", measurement: "oz"}
I'd like to match based on the name and measurement keys. I.e. if the name is the same AND the measurement is the same, then combine the object and total the qty, where the resulting object would be:
0: {name: "1", qty: "3", measurement: "Tbsp"}
1: {name: "paprika", qty: "2", measurement: "Tbsp"}
2: {name: "onion", qty: "1", measurement: "cup"}
3: {name: "tomatoes", qty: "32", measurement: "oz"}
I've tried it a few ways using .includes() and .some() but haven't managed with any success yet. Any help appreciated.