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

191
Views
Mapa en el mapa: TypeError: no se pueden leer las propiedades de undefined (leyendo 'mapa')

tengo estos datos:

 [ { "id": "1", "name": "test1", "secondary": [ "testS1", "testS2" ] }, { "id": "2", "name": "test2", "secondary": [ "testS3", "testS4" ] } ]

Mapeo todos los ejercicios de un archivo json, y ahora deseo hacer un bucle de props.exercices.secondary de cada objeto. Aquí está mi intento:

 export default function AllExos(props) { return <div> {props.exercices.map(exo => { return <div key={exo.name}> <div> <h2>{exo.id}</h2> <p>Display secondary : {exo.secondary.map(k => { return <span key={k}>{k}</span> })} </p> </div> </div> })} </div> }

No entiendo por qué aparece el error TypeError: Cannot read properties of undefined (reading 'map') . Estoy haciendo un bucle en los 'props.exercices', ¿verdad?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Prueba esta condición props.exercices && props.exercices.length > 0 &&

 export default function AllExos(props) { return <div> {props.exercices && props.exercices.length > 0 && props.exercices.map(exo => { return <div key={exo.name}> <div> <h2>{exo.id}</h2> <p>Display secondary : {exo.secondary.map(k => { return <span key={k}>{k}</span> })} </p> </div> </div> })} </div> }
about 4 years ago · Juan Pablo Isaza Report

0

Puede utilizar el encadenamiento opcional.

 props?.exercices?.map(...)
about 4 years ago · Juan Pablo Isaza Report
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!