As I continue to learn JavaScript, I have encountered something that is confusing me.
Within my Vue data object, I have the following properties:
data: {
allergenFilter: [],
categoryFilter: [],
results: {},
},
I am using an array of checkboxes to select allergens for products, which then populates my allergenFilter
Vue property like this:
[
0: "nut-free",
1: "milk-free"
]
Additionally, I have a list of allergens that a product may or may not have, and I want to filter products based on these choices. Here is an example of allergens from a product:
[
0:"vegetarian"
1:"vegan"
2:"egg-free"
3:"nut-free"
]
I attempted to filter the results by using the following code:
this.results.filter(result =>
result.allergens.includes(
this.allergenFilter
)
)
Unfortunately, this approach didn't work due to the mismatch in key-value pairs. I understand the issue, but I am uncertain about how to determine if the values in one array are included in the values of another array.