Seeking assistance with creating a function to filter an array of objects using another array as reference values. For example:
The array containing objects:
const persons = [
{
personId: 1,
name: 'Patrick',
lastName: 'Smith',
age: 27,
allergy: [
{
idAllergy: 1,
name: 'Fish'
},{
idAllergy: 2,
name: 'Nuts'
}
]
},
{
personId: 2,
name: 'Lara',
lastName: 'Blake',
age: 21,
allergy: [
{
idAllergy: 2,
name: 'Nuts'
}
]
},
{
personId: 3,
name: 'Erick',
lastName: 'Robinson',
age: 30,
allergy: [
{
idAllergy: 3,
name: 'Flowers'
}
]
},
{
personId: 4,
name: 'Hilda',
lastName: 'Vianne',
age: 35,
allergy: [
{
idAllergy: 4,
name: 'Chocolat'
}
]
}
]
The array with values for filtering:
// These are idAllergy let allergy = [2,3]
The goal is to use the values in the "allergy" array to search within the "persons" array and exclude individuals allergic to nuts and flowers. The expected result would be:
[{
personId: 4,
name: 'Hilda',
lastName: 'Vianne',
age: 35,
allergy: [
{
idAllergy: 4,
name: 'Chocolat'
}
]
}]
Appreciate any help provided.