I have an array of results. I want to filter the results to an array whose categorys have at least one object with a cat_id of 1. How can I do that?
"results": [
{
"product_id": 1,
"title": "booking",
"draft": false,
"publish": true,
"category": [
{
"cat_id": 1,
"cat_name": "web",
"product": "booking"
}
],
},
{
"product_id": 2,
"title": "reading",
"draft": false,
"publish": true,
"category": [
{
"cat_id": 6,
"cat_name": "android",
"product": "asdasd"
}
],
},
{
"product_id": 3,
"title": "reading",
"draft": false,
"publish": true,
"category": [],
},
]
My attempt:
for (let i = 0; i < data.results.length; i++) {
this.webCatProducts = data.results[i].category.filter(d => d.cat_id == 1)
console.log(this.webCatProducts)
}