Let's say I have an array of products:
const products = [
{ title: 'test product', storefront: {id: 0, title: 'test storefront 1'} },
{ title: 'test product 2', storefront: {id: 0, title: 'test storefront 1'} },
{ title: 'test product 3', storefront: {id: 1, title: 'test storefront 2'} }
]
How would I return a new array that will contain an object for each storefront and all it's products?
For example:
const storefronsts = [
{
storefront: {id: 0, title: 'test storefront 1'},
products: [
{ title: 'test product', storefront: {id: 0, title: 'test storefront 1'} },
{ title: 'test product 2', storefront: {id: 0, title: 'test storefront 1'} }
]
},
{
storefront: {id: 1, title: 'test storefront 2'},
products: [
{ title: 'test product 3', storefront: {id: 1, title: 'test storefront 2'} }
]
}
]