I have a comma-separated string that I want to convert into an array, so I can loop through it.
Is there anything built-in to do this?
For example, I have this
I had a similar issue, but more complex as I needed to transform a CSV file into an array of arrays (each line is one array element that inside has an array of items split by comma).
The easiest solution (and more secure I bet) was to use PapaParse which has a "no-header" option that transform the CSV file into an array of arrays, plus, it automatically detected the "," as my delimiter.
Plus, it is registered in Bower, so I only had to:
bower install papa-parse --save
And then use it in my code as follows:
var arrayOfArrays = Papa.parse(csvStringWithEnters), {header:false}).data;
I really liked it.