How to convert comma separated string to array using JavaScript

Here is the explanation how to use jQuery to split string with comma or jQuery split string into array by comma or jQuery split comma separated string into array with example. By using split() function in we can split string with comma or space etc. based on requirement in jQuery.

Split function use a seperater to convert in to array.

var string = "0.47,0.69,0.70,0.89,0.95,1.10,1.20,1.35";
var array = string.split(',');
console.log(array);

Ouptput

Array [ "0.47", "0.69", "0.70", "0.89", "0.95", "1.10", "1.20", "1.35" ]

Another Example

var string = "A,B,C,D,E,10,20";
var array = string.split(',');
console.log(array);

Output

Array [ "A", "B", "C", "D", "E", "10", "20" ]

Leave a Reply

Your email address will not be published. Required fields are marked *