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…

let brandStr: string = 'Infinitbility,Reapirbility,Notebility';

// lets convert it in array
let brandArray: Array<string> = brandStr.split(",");

console.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 đź‘Ť.