OneCompiler

[JavaScript] How to convert comma separated string into an array?

I want to convert a comma separated string into an array, how to do that in Javascript?

1 Answer

4 years ago by

split() method is used to convert a string in to an array.

Usage:

string.split(separator, limit)

Example:

let colors = 'red,blue,green,yellow';
console.log(colors.split(','));

Run here https://onecompiler.com/javascript/3xnkk4596

4 years ago by Meera