创建仅包含现有数组重复项的新数组

时间:2021-01-16 12:39:44

标签: arrays filter cart

我正在开发一个电子商务应用程序,我想在其中提取有多少产品被复制和复制的因素是什么。

为了更简洁,我想从仅包含重复项的现有篮子数组中过滤出一个新数组:

const basket = [{id: "15", title: "Product5", price: 199.99},
                {id: "12", title: "Product4", price: 300},
                {id: "15", title: "Product5", price: 199.99},
               ]

我希望篮子按id过滤;喜欢

const newBasket = [{id: "15", title: "Product5", price: 199.99},
                   {id: "15", title: "Product5", price: 199.99}
               ]

我是初学者,所以我什至不知道如何做到这一点。我尝试过basket.filter(),但无法构建逻辑。

提前致谢。

0 个答案:

没有答案