javascript - 如何使用 ID 数组过滤我的对象列表 - Angular/TypeScript
问题描述
我想用数组过滤以下代码。
MyArray = ['1','2,'3']
this.productlist = listComesFromASubscription.filter((product: Product) => product.productId === this.MyArray;
有人可以帮我吗 ?我只想让产品列表中包含来自 Array MyArray 的 Id 的产品。
解决方案
MyArray = ['1','2,'3']
this.productlist = listComesFromASubscription.filter((product: Product) => this.MyArray.includes(product.productId))
推荐阅读
- vb.net - 如何将“日期”类型数组转换为“字符串”类型数组 (VB)
- python - 如何将pyramid_beaker 装饰器风格的缓存和pyramid_tm 结合起来?
- java - Draw Box 有效,但 Line 无效
- c++ - 将 Vector 作为引用传递给 Std::Tuple 并对其进行修改
- django - 我可以在 django 中的 HTML 中添加表单吗
- apache-spark - 无法读取 csv pyspark
- python - 如何正确塑造 keras 模型的输入数据?
- python-3.x - 使用 tensorflow 2.4.1 训练模型时出现问题
- r - 如何从服务器下载图像,然后使用 R 将其上传到网站?
- python - 如何在 sklearn 中进行多词标记化?