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

157
Views
Typescript concat string to string if he is avaialble

I have some values like this

let originalString = 'original'

let text1 = 'string1';
let text2 = 'string2';

I need to concat those text values in originalString, and final string should look like this

let originalString = 'original/string1/string2';

The problem I have is that sometimes one of the text string can be null, and then it has to remove from originalString, here is example with null

When second is null

let originalString = 'original'

let text1 = 'string1';
let text2 = null;

let originalString = 'original/string1';

When is null

let originalString = 'original'

let text1 = 'null';
let text2 = 'null';

let originalString = 'original';

And so on, maybe sometimes even all can be null, or two of them, anyway I need to add them in new string

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

0

You can push all of them into an array, and then your final array can be like this

const stringArray = ["original", null, "string2"]

Finally, you can use a filter to get NOT null values and then join them all

originalString = stringArray.filter(x => x).join("/")

In your example, you're also using a 'null' string for values. You can add that value into your filter too.

originalString = stringArray.filter(x => x && x !== 'null').join("/")
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!