I've got an object describing various dog types, as well as variables describing the dog I'm looking for:
const dogs = [
{
"breed": "german shepherd",
"size": ["large"],
"temperment": ["trait 1","trait 3"]
},
{
"breed": "poodle",
"size": ["small","medium","large"],
"temperment": ["trait 1","trait 2","trait 3"]
},
{
"breed": "terrier",
"size": ["small","medium"],
"temperment": ["trait 1","trait 2"]
}
]
const idealSize = ["medium"] //ideal match can include other sizes as well
const idealTemperment = ["trait 1","trait 2"] //ideal match would possess NO other traits
I've got a specific dog size and dog temperament I'm looking for that both need to match. Dog temperament should match exactly.
Here's what I currently have:
const filteredDogs = dogs.find((dog) => {
return idealSize.every(e => dog.size.includes(e));
});
console.log(filteredDogs)
It's currently only looking for a "size" match, and I'm unsure of how to also match the "temperament" [exclusively].
The ideal outcome would be:
"breed": "terrier",
"size": ["small","medium"],
"temperment": ["trait 1","trait 2"]