Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split comma separated string using JavaScript? [duplicate]

Tags:

javascript

People also ask

How do you convert a string separated by a comma to an array?

Use the String. split() method to convert a comma separated string to an array, e.g. const arr = str. split(',') . The split() method will split the string on each occurrence of a comma and will return an array containing the results.

How Split comma separated Values in HTML?

To convert comma separated text into separate lines, you need to use trim() along with split() on the basis of comma(,).

Can we divide string in JavaScript?

You can split a string by each character using an empty string('') as the splitter. In the example below, we split the same message using an empty string. The result of the split will be an array containing all the characters in the message string.


var partsOfStr = str.split(',');

split()


var array = string.split(',')

and good morning, too, since I have to type 30 chars ...


var result;
result = "1,2,3".split(","); 
console.log(result);

More info on W3Schools describing the String Split function.


Use

YourCommaSeparatedString.split(',');