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

217
Views
Ignore undefined value when concatenating words split by comma?

I would like ignore the initial value undefined of string variable, I'm trying concatenate words separate by comma but the first concatenation is an undefined. I can not use array of string.

Can it ignore undefined value?

MyComponent.ts

  addTag(tag: any){
    this.tags = `${this.asunto.etiquetas}, ${tag}`;
    (<HTMLInputElement>document.getElementById("tags")).value = '';
  }

View of my angular component

enter image description here

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

0

You should put the etiquetas when available, otherwise an empty string. Since you can write normal Javascript inside that template literal:

  addTag(tag: any){
    this.tags = `${this.asunto.etiquetas ? `${this.asunto.etiquetas}, ` : ""} ${tag}`;
    (<HTMLInputElement>document.getElementById("tags")).value = '';
  }

A better version would be to just use a variable

  addTag(tag: any){
    const etiqueta = this.asunto.etiquetas ? `${this.asunto.etiquetas}, `} : "";
    this.tags = `${etiqueta}${tag}`;
    (<HTMLInputElement>document.getElementById("tags")).value = '';
  }
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!