I am trying to convert a comma separated string into an array using the split method(Convert comma separated string to array).
This is the code:
var nameList = "milk,sugar,flour";
var nameArray = nameList.split(',');
document.write('The nameList is: ' + nameList);
document.write('<br />');
document.write('The nameArray is: ' + nameArray);
This is the output:
The nameList is: milk,sugar,flour
The nameArray is: milk,sugar,flour
It looks to me like it is still a string separated by commas. Why is the comma-separated string not converting to an array using split() in javaScript?