I\'ve followed this post How to export JavaScript array info to csv (on client side)? to get a nested js array written as a csv file.
The array looks like:
The selected answer is probably correct but it seems needlessly unclear.
I found Shomz's Fiddle to be very helpful, but again, needlessly unclear. (Edit: I now see that that Fiddle is based on the OP's Fiddle.)
Here's my version (which I've created a Fiddle for) which I think is more clear:
function downloadableCSV(rows) {
var content = "data:text/csv;charset=utf-8,";
rows.forEach(function(row, index) {
content += row.join(",") + "\n";
});
return encodeURI(content);
}
var rows = [
["name1", 2, 3],
["name2", 4, 5],
["name3", 6, 7],
["name4", 8, 9],
["name5", 10, 11]
];
$("#download").click(function() {
window.open(downloadableCSV(rows));
});