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

249
Views
How to show comma seperated value from array of object

I am trying to show array's object key comma separated, But I am getting extra comma(,) in starting.

getSeperatedByCommaName(): string {
    let finalName = '';
    this.options.Ids.forEach((value) => {
      finalName = finalName + ',' + value.Name;
    })
    return finalName;
  }

Am I doing something wrong? Or is there any way to display directly comma separated on html without writing above function?

Thanks in advance

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

0

Use join method:

let commaSeparatedNames = this.options.Ids.map(itm => itm.Name).join(',');
about 4 years ago · Juan Pablo Isaza Report

0

Normal way: Demo

get seperatedByCommaName(): string {
    return this.options.Ids.map(value => value.Name).join(",");
}

In template:

<p>{{ seperatedByCommaName }}</p>

Another way Using pipe : Demo

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'join'
})
export class JoinPipe implements PipeTransform {
  transform(input: Array<any>, sep = ', '): string {
    return input.map(value => value.Name).join(sep);
  }
}

Don't forget to declare JoinPipe in module like:

@NgModule({
  imports: [],
  declarations: [ 
    JoinPipe
  ],
  exports: [
    JoinPipe  // if to be made available outside modules
  ]
})

In Template

<p> {{ options.Ids | join }} </p>
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!