How to Convert Array into Comma Separated String in Angular?

By Hardik Savani May 2, 2024 Category : Angular

Here, i will show you how to works angular convert array to string. this example will help you angular array to comma separated string. if you want to see example of angular convert array to comma separated string then you are a right place. if you want to see example of how to convert array to comma separated string in angular then you are a right place.

I will give you very simple example of convert array to comma separated string angular application. you can easily convert array to string in angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, angular 15, angular 16 and angular 17 project.

we will use toString() array function to converting array to string in angular app. toString() provide to covert array into comma separated string. so let's see bellow example that will help you easily understand.

you can see example with output:

src/app/app.component.ts

import { Component } from '@angular/core';

@Component({

selector: 'my-app',

templateUrl: './app.component.html',

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

name = 'Angular';

myArray = ['Hardik', 'Paresh', 'Vimal', 'Harshad', 'Kiran'];

myString = this.myArray.toString();

}

src/app/app.component.html

<p>{{ myString }}</p>

<p>{{ myArray.toString() }}</p>

Output:

Hardik,Paresh,Vimal,Harshad,Kiran

Hardik,Paresh,Vimal,Harshad,Kiran

I hope it can help you...

Shares