Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
Conditionally include text between multiple values?

I have this, which works, but some fields don't always have values (& don't render). Is there a way to include text conditionally? For example, between {a}, {b} & {c}, but only if they are both rendered?

const yay = `${a ? a + ` | `: ""}${b ? b + ` | ` : ""}${c ? c : ""}`
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can add all of them in an array and filter them based on their truthy value evaluation in javascript. Later, just join the result as a string delimited by |.

let a = "789";
let b = "";
let c = true;

const result = [a,b,c].filter(ele => ele);

console.log(result.join('|'))

about 4 years ago · Juan Pablo Isaza Denunciar

0

You could use [a, b, c].filter(v => !!v).join('|'). This filters out all falsy values (undefined, null, false, 0, empty string, etc), which is what your current code is doing as well.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda