Skip to content

Instantly share code, notes, and snippets.

@feload
Last active January 30, 2017 18:25
Show Gist options
  • Save feload/37f94449b924b8f3483cd4f482c38230 to your computer and use it in GitHub Desktop.
Save feload/37f94449b924b8f3483cd4f482c38230 to your computer and use it in GitHub Desktop.
This script allows you create a csv on the fly.
var A = [['n','sqrt(n)']];
for(var j=1; j<10; ++j){
A.push([j, Math.sqrt(j)]);
}
var csvRows = [];
for(var i=0, l=A.length; i<l; ++i){
csvRows.push(A[i].join(','));
}
var csvString = csvRows.join("%0A");
var a = document.createElement('a');
a.href = 'data:attachment/csv,' + csvString;
a.target = '_blank';
a.download = 'myFile.csv';
document.body.appendChild(a);
a.click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment