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

228
Views
¿Cómo hacer que una matriz de objetos en javascript reaccione si no está definido?

Quiero verificar la matriz vacía en reaccionar JavaScript. Pero cuando estoy usando el signo de interrogación para verificar si está indefinido o no, entonces reacciona y se bloquea.

Estoy usando algo como esto:

 const [verlist, setverlist] = useState([]);

En el gancho useEffect estoy usando setverlist(response.versions.version) . Aquí las versions son objeto. Y en su version hay una matriz de objetos.

Pero cuando obtengo versiones como objeto vacío {} , mi aplicación de reacción falla porque en la consola no estoy definido.

Estoy renderizando así:

{[...verlist].reverse().map((value, id) => {})}

Cómo puedo solucionar esto ?

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

0

Puede poner una marca delante de su código.

verlist && verlist.length > 0 && [...verlist].reverse().map((value, id) => {})

Déjame saber si funciona.

about 4 years ago · Juan Pablo Isaza Report

0

Cambio

de: [...verlist].reverse().map((value, id) => {})

a: verlist.length > 0 && [...verlist].reverse().map((value, id) => {})

about 4 years ago · Juan Pablo Isaza Report

0

Si verlist es una matriz y puede no estar definida, intente:

 verlist && verlist.length && [...verlist].reverse().map((value, id) => {})
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!