My JSON file contains objects structured like this:
[
{
"name" : "something",
"brand": "x",
"category" : "cars"
},
{
"name" : "something2",
"brand": ["x", "y"],
"category" : "bikes",
}
]
When filtering by category
, my function works fine. Here's how it looks:
filterObjects(key, value) {
if (key == 'category') {
return objects.filter(item => item.category == value);
}
}
However, when I try to filter by brand
, only the first item is returned. How can I adjust my filter function to loop over each value and return all matching items?