I have an array, which looks like this:
const persons = [
{
name: \"Joe\",
animals: [
{species: \"dog\", name: \"Bolt\"},
{species: \"c
Your inner filter still returns a "truthy" value (empty array) for the dog person. Add .length
so that no results becomes 0
("falsey")
const result = persons.filter(p => p.animals.filter(s => s.species === 'cat').length)
Edit: Per comments and several other answers, since the goal is to get a truthy value from the inner loop, .some
would get the job done even better because it directly returns true if any items match.
const result = persons.filter(p => p.animals.some(s => s.species === 'cat'))