ItSolutionStuff.com

How to Convert Comma Separated String to Array in Angular?

By Hardik Savani • May 2, 2024
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

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Angular Input Focus Event Example

Read Now →

Angular - How to Find and Update Object in Array?

Read Now →

How to Push Object in Array in Angular?

Read Now →

Angular How to Remove Element from Array?

Read Now →

Angular Check ngIf Null or Empty | Angular Check If Array is Empty

Read Now →

Angular Checkbox Example | Angular 9/8 Checkbox Tutorial

Read Now →

How to Create Component in Angular 9?

Read Now →

Angular 9/8 Bootstrap Collapse Example

Read Now →

How to use Highcharts in Angular?

Read Now →

How to Create Custom Validators in Angular 9/8?

Read Now →

Angular NgClass - How to Add Dynamic Class in Angular 10/9/8?

Read Now →