I have my array object in the following format
menuItem = [{
"name": "MOZZARELLA DI BUFALA & TOMATOES",
"gluten": true,
"eggs": false,
"dairy": true,
...
},...
I want to filter hundreds of menuItems by the allergen values (Boolean).
While the following code does the trick:
menuItem.filter(el => !el.gluten && !el.fish && !el.soy && !el.dairy)"
The allergens are hardcoded and repetitive. I am struggling to make the code dynamic and elegant.
I tried the following solution
menuItem.filter(el => !el[allergens])"
var allergens = ['gluten', 'fish', 'soy', 'dairy']
However, it only works correctly with one allergen value. Multiple values as in the above example do not filter anything.
menuIten.filter(el => Object.keys(el).filter(i => (typeof i === "boolean").every(i => !i));