Given the following array of objects:
var data = [
{fruit: "apples", stock: false, season: true},
{fruit: "peaches", stock: true, season: false},
{fruit: "oranges", stock: false, season: false},
{fruit: "pears", stock: false, season: true},
]
and these two arrays:
var fruits = ["apples", "peaches"]
var inv = ["stock"]
How can I filter the objects, from data, so that objects are kept:
- if they have a
fruitin thefruitsarray; AND - they have a property from the
invarray which is set to true
So, in the above example, only peaches survive:
var result = [
{fruit: "peaches", stock: true, season: false}
]
invarray which is set to true"? does a single property has to be set totrue, or if more all?