Hi I have problem with parse CSV file in JavaScript. Structure CSV below
<code>
date, hours, text
2004-05-04,05:22, Sample text, with coma
2005-05-04,05:22:00, Another Sample text, with coma
2006-05-04,05:22, Third Sample text, with coma
</code>
To parse this CSV I use code below
<code>
$.ajax({
type: "GET",
url: "data.csv",
dataType: "text",
success: function(data) {processData(data);}
});
function processData(csv) {
var allTextLines = csv.split(/\r\n|\n/);
//console.log(allTextLines);
var lines = [];
while (allTextLines.length) {
//console.log(allTextLines);
lines.push(allTextLines.shift().split(","));
}
console.log(lines);
}
</code>
The problem is, when i have comma inside text I have array like this
<code>
lines[0]=['2004-05-04']['05:22'][Sample text][with comma];
</code>
My question is, how to convert this to array like this one:
<code>
lines[0]=['2004-05-04']['05:22'][Sample text, with coma];
</code>
Thanks for help!