I have a long string containing CSV data from a file. I want to store it in a JavaScript Array of Arrays. But one column has arbitrary text in it. That text could contain double-quotes and commas.
Splitting the CSV string into separate row strings is no problem:
var theRows = theCsv.split(/\r?\n/);
But then how would I best split each row?
Since it's CSV data I need to split on commas. But
var theArray = new Array();
for (var i=0, i<theRows.length; i++) {
theArray[i] = theRows[i].split(',');
}
won't work for elements containing quotes and commas, like this example:
512,"""Fake News"" and the ""Best Way"" to deal with A, B, and C", 1/18/2019,media
How can I make sure that 2nd element gets properly stored in a single array element as
"Fake News" and the "Best Way" to deal with A, B, and C
Thanks.
The suggested solution which looked similar unfortunately did not work when I tried the CSVtoArray function there. Instead of returning array elements, a null value was returned, as described in my comment below.