In Vue3, I am working with the object $products, which looks like this:
[{
"id": 1,
"item": "Product 1",
"productcategories": [{
"id": 300,
"title": "Category300"
},
{
"id": 301,
"title": "Category301"
}],
},
{
"id": 2,
"item": "Product 2",
"productcategories": [{
"id": 200,
"title": "Category200"
}],
},
{
"id": 3,
"item": "Product 3",
"productcategories": [{
"id": 301,
"title": "Category301"
},
{
"id": 309,
"title": "Category309"
}],
}]
It's important to note that each product can belong to multiple product categories.
My objective is to filter this object and retrieve a new object that includes only products with at least one product category id of 301. The resulting object, $filtered_products, should look like this:
[{
"id": 1,
"department_id": 2,
"item": "Product 1",
"productcategories": [{
"id": 300,
"title": "Category300"
},
{
"id": **301**,
"title": "Category301"
}],
},
{
"id": 3,
"department_id": 2,
"item": "Product 1",
"productcategories": [{
"id": **301**,
"title": "Category301"
},
{
"id": 309,
"title": "Category309"
}],
}]
I am looking for recommendations on how to optimize this search process for efficiency.