I have a an array of products which I loop though and display them on an item. However it can happen that the same product gets chosen multiple times the same day and I therefore want the quantity to be displayed correctly but I'm not sure how to do that.
So my array looks forexample like this:
[
{product_id: "679", quantity: "1", chosen_date: "2018-10-01"}
{product_id: "675", quantity: "1", chosen_date: "2018-10-02"}
{product_id: "675", quantity: "1", chosen_date: "2018-10-02"}
{product_id: "675", quantity: "1", chosen_date: "2018-10-03"}
]
And here is my loop which displays each item
let elementWrapper = document.querySelectorAll('.items')
for (var i = 0; i < items.length; i++){
let elem = elementWrapper[i];
let chosen_date = items[i].chosen_date;
let product_id = items[i].product_id;
let quantity = items[i].quantity;
let span = document.createElement('span');
span.innerHTML = moment(chosen_date).locale('da').format('Do MMM');
elementWrapper[i].append(span);
}
where "items" is the array.
Like mentioned above, I want the product with the ID "675" which is chosen twice the "2018-10-02" to be displayed only once, with the quantity = 2
How can I achieve that?