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

154
Views
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 answers
Answer question

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 Report

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 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!