Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!