Created
March 14, 2019 16:58
-
-
Save techb/1621c4fae80916b39cd5679abab085fc to your computer and use it in GitHub Desktop.
JS Array to CSV Download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var csv_arr = []; | |
// add header first before pushing data | |
csv.push(["Bruh", "Data", "Date", "Ect"]); | |
for(var i = 0; i <= somedata.length; i++){ | |
csv_arr.push(somedata[i]); | |
} | |
// found: https://gist.github.com/yangshun/01b81762e8d30f0d7f8f | |
document.querySelector("#muh_epic_button").addEventListener("click", function () { | |
var csvString = csv_arr.join('\r\n'); // Windows newline | |
var a = document.createElement('a'); | |
a.href = 'data:attachment/csv,' + csvString; | |
a.target = '_blank'; | |
a.download = 'data.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