I have this JSON response I want to filter out the product that contains specific id inside the categories arrays
[
{
"id": 7721,
"name": "Grilled kebab corn tomato special",
"purchase_note": "",
"categories": [
{
"id": 50,
"name": "All recipes",
"slug": "0-all-recipes"
},
{
"id": 94,
"name": "Chef's Special",
"slug": "chefs-special"
}
]
},
{
"id": 7722,
"name": "Grilled kebab corn tomato special",
"purchase_note": "",
"categories": [
{
"id": 112,
"name": "All recipes",
"slug": "0-all-recipes"
},
{
"id": 22,
"name": "Chef's Special",
"slug": "chefs-special"
}
]
}
]
Here's an example I want to filter out the object that contains id 112 in the categories array let's say I want this result from the JSON object given above
[
{
"id": 7722,
"name": "Grilled kebab corn tomato special",
"purchase_note": "",
"categories": [
{
"id": 112,
"name": "All recipes",
"slug": "0-all-recipes"
},
{
"id": 22,
"name": "Chef's Special",
"slug": "chefs-special"
}
]
}
]
In JavaScript
Thanks (:
That's what I have tried and it's working to filter out depends on the string inside the objects but I couldn't find a way to filter out depends on the categories id
here's my try
menuData = the json response
menuData.filter(menuData => menuData.name == "Grilled kebab corn tomato special");
also, I've tried to use this
menuData = the json response
menuData.filter(menuData => menuData.categories.map((o) => o.id) == 112);