I have an array of arrays, which looks something like this:
rows = [
[Name, Description, Number ...],
["A thing", "Description, but it has commas in it", 6, ...],
...
]
I am trying to download this as a csv file. Here’s the code I have so far:
// Make a csv from rows
let csv = rows.map(row => row.join(",")).join("n");
document.getElementById("csv_download").setAttribute("download", "file_name.csv");
document.getElementById("csv_download").href = "data:text/csv;charset=utf-8," + encodeURIComponent(csv);
This works fine when there are no commas inside the array, but right now it sees the comma after “Description” and splits it there. I also can’t split it by “, because some of the items are numbers.
How do I go about solving this?