I have an object array called filteredAnimals that returns the animals which are present in a given filter.
if (!dog.present) { filteredAnimals = filteredAnimals.filter( e => !e.animal_type.includes('Dog'), ); }if (!cat.present) {
filteredAnimals = filteredAnimals.filter(
e => !e.animal_type.includes(‘Cat’),
);
}if (!fish.present) {
filteredAnimals = filteredAnimals.filter(
e => !e.animal_type.includes(‘fish’),
);
}
Is there a way to combine this in one call? I’m a bit stumped because the call won’t be made unless the conditional is met. I was thinking of making a function but I feel there’s a better way to do this.
#javascript