I am currently working with two specific objects:
clinics: [
{
id: 1,
name: 'New Hampshire Veterinarian Clinic',
plans: [
'handle123',
'handle567',
]
},
{
id: 2,
name: 'Westminster Moltchester Clinic',
plans: [
'handle123',
'handle789',
]
}
],
animals: [
{
id: 1,
handle: 'handle123',
name: 'Cat',
},
{
id: 2,
handle: 'handle567',
name: 'Dog',
},
{
id: 3,
handle: 'haneld789',
name: 'Horse'
}
],
In my code, I have the following function:
updateAnimals(selectedOption, id) {
}
The parameter selectedOption
represents an object from the clinics
array.
My objective is to filter the second array so that it only includes the handles mentioned in the selected option. However, I am encountering difficulties with the parameters. I want to accomplish something similar to this:
updateAnimals(selectedOption, id) {
let filteredAnimals = this.animals.filter(function({id, handle, name}) {
// I need to access the selectedOption here in order to use it for filtering
});
}
Yet, I am uncertain about how to access the selected option within the function... Is there perhaps a more effective way to achieve this?