How to Convert Array into Comma Separated String in Angular?

By Hardik Savani | July 14, 2020 | 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 and angular 9 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...




Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: