I have an array of objects that looks similar to this:-
// The array ("shoppingCart") could contain lots of different "products", by lots of different "sellers".
const shoppingCart = [
{
product: { product: 34, seller: 1 },
quantity: 43
},
{
product: { product: 2, seller: 2 },
quantity: 65
},
{
product: { product: 7, seller: 1 },
quantity: 23
},
{
product: { product: 5, seller: 2 },
quantity: 75
}
];
I need to map through these objects, in order to render this desired view: shopping cart data rendered
How can I restructure this array so that it is sorted by Seller and in a structure which can then be mapped through in order to render "Seller Cart Component(s)", with the products passed through as props (so they can be mapped into "Product Cart Component(s)" later on)?
Note: ideally the sellers should be organised in the order in which they appear in the "shoppingCart" array. i.e. if product 34 were to contain the key-value pair "seller: 2", then seller 2's "Seller Cart Component" would render first.