【发布时间】:2021-06-25 23:48:02
【问题描述】:
假设我有一系列产品:
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'} }
]
如何返回一个包含每个店面及其所有产品的对象的新数组?
例如:
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'} }
]
}
]
【问题讨论】:
-
@MisterJojo 哎呀。现已修复。
标签: javascript arrays typescript sorting ecmascript-6