Skip to content

Instantly share code, notes, and snippets.

@Falciighol
Created March 10, 2020 04:01
Show Gist options
  • Save Falciighol/174ed083bc95491a80b538b64eab24f0 to your computer and use it in GitHub Desktop.
Save Falciighol/174ed083bc95491a80b538b64eab24f0 to your computer and use it in GitHub Desktop.
[CSV from Array]
const rows = [
["name1", "city1", "some other info"],
["name2", "city2", "more info"]
];
let csvContent = "data:text/csv;charset=utf-8," + rows.map(e => e.join(",")).join("\n");
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "my_data.csv");
document.body.appendChild(link); // Required for FF
link.click(); // This will download the data file named "my_data.csv".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment