Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

250
Visualizações
How to target a specific array inside an array using map

Image illustration of what I'm trying to get:

screenshot console, pointing to nested indexes (3,0) and (3,1)

I'm mapping through this parent array with an array of children that has an object children.

I'm trying to use logic to decide which array should be edited with destructuring, then passing the result back to a state. here's my code below. Thanks

Edit: I just fixed the code by adding an "=" sign instead of a ":". But this time, it is working halfway by adding a new value instead of modifying the existing array I'm trying to target with [eventId]

function toggleSelectedOption(event, id) {
  let eventId = event.target.id

  setSelectOption(prevState => {
    return prevState.map((each, index) => {
      if (index === id ) {
      
        return [...each, each[eventId] =  {...each[eventId], isSelected: !each[eventId].isSelected}]
      }else {
        return each;
      }

    })
  })

}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda