I managed to count every repeated element in my array, now I just want to display only one and each product quantity quantity.
This is what I have now:
I have a function which I am exporting from a file called Helpers.js and then using in my Vue component.
Helpers.js:
export const groupBy = (arr, criteria) => {
return arr.reduce((obj, item, index) => {
const key = typeof criteria === 'function' ? criteria(item, index) : item[criteria];
if (!obj.hasOwnProperty(key)) {
obj[key] = [];
}
obj[key].push(item);
return obj;
}, {});
}
Orders Component:
import { groupBy } from "@/Utils/Helpers";
... rest of the component...
const groupedOrders = computed(() => groupBy(props.order.products, (product) => product.id));
This is in my template:
<div class="mt-5 mx-8" v-for="products in groupedOrders">
{{ products.length }}
<OrderItem
v-for="(product, index) in products"
:product="product"
:key="index"
/>
</div>
This is the data which I am loggin in the console:
Any clue how to make it to show only one Modi and display the quantity, something like Modi (Qtty. 4)

