How to Convert Comma Separated String to Array in Angular?
Here, i will show you how to works how to convert array into comma separated string in angular. you will learn convert string into array angular. if you want to see example of convert comma separated string to array angular then you are a right place. In this article, we will implement a convert comma separated string to json array angular.
I will give you very simple example of convert comma separated string to array angular application. you can easily convert string to array 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 split() function to converting string to array in angular app. split() provide to covert comma separated string to array. so let's see bellow example that will help you easily understand.
Syntax:
split(separator, limit)
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';
myString = 'Hardik,Paresh,Vimal,Harshad,Kiran';
myArray = this.myString.split(',');
constructor() {
console.log(this.myArray);
}
}
Output:
["Hardik", "Paresh", "Vimal", "Harshad", "Kiran"]
0: "Hardik"
1: "Paresh"
2: "Vimal"
3: "Harshad"
4: "Kiran"
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Angular Input Focus Event Example
- Angular - How to Find and Update Object in Array?
- How to Push Object in Array in Angular?
- Angular How to Remove Element from Array?
- Angular Check ngIf Null or Empty | Angular Check If Array is Empty
- Angular Checkbox Example | Angular 9/8 Checkbox Tutorial
- How to Create Component in Angular 9?
- Angular 9/8 Bootstrap Collapse Example
- How to use Highcharts in Angular?
- How to Create Custom Validators in Angular 9/8?
- Angular NgClass - How to Add Dynamic Class in Angular 10/9/8?