0
const slides = [
    {title: 'one', status: 1, slides: [
        {name: 'first', id: 1},
        {name: 'second', id: 2},
        {name: 'third', id: 3},
        {name: 'fourth', id: 4},
    ]},
    {title: 'two', status: 1, slides: [
        {name: 'all', id: 1}
    ]},
]

I have this array with objects inside, and a field of these objects is an array(SLIDES), my goal is to show only the objects that have the NAME field in the SLIDES equal to 'first' and 'all'. I would need to put them in a single array in order to go and do the MAP later.

My goal is to have this:

const slides = [
    {title: 'one', status: 1, slides: [
        {name: 'first', id: 1},
    ]},
    {title: 'two', status: 1, slides: [
        {name: 'all', id: 1}
    ]},
]

Thanks to anyone who can help me.

  • What is the problem you have in doing this? If you search for "array filter javascript" you'll have plenty to research... What did you find? Did you try it? What happened? – trincot Mar 21 '23 at 18:30
  • You can use the `filter` and `map` methods in JavaScript: const filteredSlides = slides.map(obj => ({ ...obj, slides: obj.slides.filter(slide => slide.name === 'first' || slide.name === 'all') })); – Nevada Mar 21 '23 at 18:37

0 Answers0