I have a function which returns a CSV string to be consumed by
anchorEle.href = `data:text/csv;charset=utf-8,${encodeURI(csvContent)}`
If I have an array like this:-
[
[
"Test,Me,Once,More",
"Successful"
],
[
"Test1,Me1,Once1,More1",
"Successful"
]
]
The construction of CSV string messes up when I have commas in my item. I cannot set a condition based on the number of commas because it's not fixed as a user requirement. I'm using the following function:-
function toCsv(arr) {
return arr.reduce((csvString, row) => {
csvString += row.join(',');
csvString += '\r\n';
return csvString;
}, '');
}
This will return:-
Test,Me,Once,More,Successful
Test1,Me1,Once1,More1,Successful
Which when I download as CSV
I wish to club Test, Me, Once, More as one item in CSV keeping the commas as it is like this:
