async function saveCSV () {
// (A) ARRAY OF DATA
var array = [
["Job", "job@doe.com", "123456"],
["Joe", "joe@doe.com", "234567"],
["Joi", "joi@doe.com", "345678"],
["Jon", "jon@doe.com", "456789"],
["Jou", "jou@doe.com", "987654"],
["Joy", "joy@doe.com", "876543"],
];
// (B) ARRAY TO CSV STRING
var csv = "";
for (let row of array) {
for (let col of row) { csv += col + ","; }
csv += "
";
}
// (C) CREATE BLOB OBJECT
var myBlob = new Blob([csv], {type: "text/csv"});
// (D) FILE HANDLER & FILE STREAM
const fileHandle = await window.showSaveFilePicker({
suggestedName : "demo.csv",
types: [{
description: "CSV file",
accept: {"text/csv": [".csv"]}
}]
});
const fileStream = await fileHandle.createWritable();
// (E) WRITE FILE
await fileStream.write(myBlob);
await fileStream.close();
}
var array = [{
x: 0,
y: 0
}];
var a = document.body.appendChild(
document.createElement("a")
);
a.download = "export.txt";
a.href = "data:text/plain;base64," + btoa(JSON.stringify(array));
a.innerHTML = "download example text";