Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

161
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda