Having an array like this(e.g. products in a basket)
[{
"name": "item 1",
"id": 1,
"price": 10
},
{
"name": "item 2",
"id": 2,
"price": 20
},
{
"name": "item 1",
"id": 1,
"price": 10
},
{
"name": "item 3",
"id": 3,
"price": 30
}]
How can I do a *ngFor
in Angular 8 in order to print an output like:
- 2x item 1, subtotal 20
- 1x item 2, subtotal 20
- 1x item 3, subtotal 30
So basically I wish to wrap up by name(or ID) the duplicate items and show only one row for them. I should also count the occurrences and the subtotal of them