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

133
Views
¿Cómo no muestra nada si una lista de valores no está definida en Javascript?

Lo siento por esto, tal vez es una pregunta fácil y básica.

Obtengo resultados de un punto final, pero algunos de estos valores pueden estar vacíos, luego en mi pantalla aparece "indefinido"

¿Cómo puedo verificar un código limpio si parte del valor no está definido y luego no muestra nada?

 myvalues() { if (!this.myendpointdata) { return ''; } const { value1, value2, value3, value4 } = this.myendpoindata.master.values; return `${value1} ${value2} ${value3} ${value4}`; }

Este es mi código. Y, por ejemplo, value2 muestra indefinido

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

0

Puede establecer cadenas vacías si sus valores no están undefined

 myvalues() { if (!this.myendpointdata) { return ''; } const { value1, value2, value3, value4 } = this.myendpoindata.master.values; return `${value1 || ""} ${value2 || ""} ${value2 || ""} ${value4 || ""}`; }

También puede recorrer valores y filtrar valores no indefinidos para mostrarlos

 myvalues() { if (!this.myendpointdata) { return ''; } const { value1, value2, value3, value4 } = this.myendpoindata.master.values; const values = Object.values({ value1, value2, value3, value4 }); return values.filter(value => !value).join(" "); }
about 4 years ago · Juan Pablo Isaza Report

0

Puedes usar operaciones ternarias:

 return `${value1 ? value1 : ''} ${value2 ? value2 : ''} ${value3 ? value3 : ''} ${value4 ? value4 : ''}`;
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!