【发布时间】:2021-07-17 08:32:25
【问题描述】:
数据
const data = [
{
id: 1,
title: "Product Red",
inventoryItem: {
inventoryLevels: {
edges: [{ node: { location: { name: "Warehouse Red" } } }],
},
},
},
{
id: 2,
title: "Product Blue",
inventoryItem: {
inventoryLevels: {
edges: [{ node: { location: { name: "Warehouse Blue" } } }],
},
},
},
];
let result = data.filter((product) => {
return product.inventoryItem.inventoryLevels.edges.forEach((inventoryLevel) => {
return inventoryLevel.node.location.name !== "Warehouse Blue";
});
});
console.log(result);
我想要做的是按位置名称过滤。我不知道如何构建基于嵌套数组的过滤。
所以我想要的结果是位置不是 Warehouse Blue。数据应该只有位置名称为仓库红色的对象。
【问题讨论】:
标签: javascript arrays filter