The following data presents a list of products along with their inventory information:
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);
I am looking to filter this data based on the location names. I am unsure how to handle nested arrays for filtering.
Therefore, my desired outcome is to have the object in the 'data' array where the location name is not 'Warehouse Blue', resulting in only the entry with the location name 'Warehouse Red' remaining.