Navigate back to the homepage

How to convert comma separated string to array in typescript?

Infinitbility
TypeScript
April 20th, 2022 · 1 min read
keep affilitate

Hi Friends 👋,

Welcome to Infinitbility ❤️!

Today, we are going to learn how to convert comma (,) separated string to array in typescript, here we will use built-in method .split() to convert string to array.

Well, we have an string which have comma ( , ) seprate data and we have to pick those data and use as array.

To do this things, we have built-in method .split() which we have to provide seprator for now it’s comma and it will return an array.

let’s dive in code…

1let brandStr: string = 'Infinitbility,Reapirbility,Notebility';
2
3// lets convert it in array
4let brandArray: Array<string> = brandStr.split(",");
5
6console.log(brandArray);

Well, when you run above code, you can able to see above string converted in array and you have some space issues, you have to use also .trim() method.

For now, let’s check the output.

Output

TypeScript, convert comma (,) separated string to array example
TypeScript, convert comma (,) separated string to array example

All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

melio affilitate

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

How to convert a string to uppercase in typescript?

TypeScript, convert a string case to uppercase example.

April 17th, 2022 · 1 min read

How to convert a string to lowercase in typescript?

TypeScript, convert a string case to lowercase example.

April 16th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]