首页 > 解决方案 > 如何使用 ID 数组过滤我的对象列表 - Angular/TypeScript

问题描述

我想用数组过滤以下代码。

MyArray = ['1','2,'3']

this.productlist = listComesFromASubscription.filter((product: Product) => product.productId === this.MyArray;

有人可以帮我吗 ?我只想让产品列表中包含来自 Array MyArray 的 Id 的产品。

标签: javascript

解决方案


MyArray = ['1','2,'3']

this.productlist = listComesFromASubscription.filter((product: Product) => this.MyArray.includes(product.productId))

推荐阅读