Within my array, I have dates, products, and product quantities. On occasions, the same products appear on the same day, and I want to combine them only if the date matches. Here is my array:
[
{date:"day2",sku:"product1",qty:1},
{date:"day1",sku:"product1",qty:1},
{date:"day1",sku:"product2",qty:1},
{date:"day2",sku:"product2",qty:1},
{date:"day1",sku:"product1",qty:1},
{date:"day2",sku:"product2",qty:1},
{date:"day2",sku:"product2",qty:1},
{date:"day3",sku:"product1",qty:3}
]
This is what I expect as output:
[
{date:"day1",sku:"product1",qty:2},
{date:"day1",sku:"product2",qty:1},
{date:"day2",sku:"product1",qty:1},
{date:"day2",sku:"product2",qty:3},
{date:"day3",sku:"product1",qty:3}
]