我有一个Products数组,像这样
Products[{product: {id: "Sss", name: "rttt", picture: "rrrrr"},
quantity: 22},{product:{id:"tt",name:"qqq",picture:"iooo"}]
let item = Products.product.find((p) => p.productId === product.id);
我想在Angular 6中找到ID为tt的产品,怎么做?
答案 0 :(得分:0)
您正在尝试将Array.find
应用于单个对象(Products.product
数组的第一项)Products
。相反,您应该在find
之上Products
。
var products = [{product :{id: "Sss", name: "rttt", picture: "rrrrr"}},{product:{id:"tt",name:"qqq",picture:"iooo"}}]
var selProd = products.find(p => p.product.id = 'tt');
console.log(selProd);