Answer the question
In order to leave comments, you need to log in
How to apply filter to nested array?
hello i have an array
const cards = [
{id:1 ,name: 'Product A', image: 'pic-001.jpg', tags: [tag: 'nature', id: f1fz2]},
{id:2 ,name: 'Product B', image: 'pic-002.jpg', tags: [tag: 'nature', id: 2fs]},
{id:3 ,name: 'Product C', image: 'pic-003.jpg', tags: [tag: 'nature', id: f11fdfz2]}
]
const name='Product A'
this.setState({
cards: cards.filter(item => item.name.includes(tag))
})
Answer the question
In order to leave comments, you need to log in
It is possible in the same way as with name - the includes method, arrays have it too:
cards.filter(n => n.tags.includes(tag))
let foo = cards.filter(item =>
item.tags.includes('winter')
&& // <-- magic is here
item.name.includes('Product B')
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question