Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

make file from array save js

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();
}
Comment

save array file

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";
Comment

PREVIOUS NEXT
Code Example
Javascript :: js rename onclick function 
Javascript :: gojs update text 
Javascript :: create multiple array buttons in javascript 
Javascript :: uncaughtException javascript 
Javascript :: round down html 
Javascript :: mongoose limit skip 
Javascript :: react usestate 
Javascript :: insertadjacenthtml trong js 
Javascript :: usenavigate and uselocation in react 
Javascript :: spawn prop with custom model 
Javascript :: js ctx dash line 
Javascript :: how to get form all filed with properties in jquery 
Javascript :: onpress not working when textinput isfocused in react native 
Javascript :: js code to accept all linkedin requests 
Javascript :: document ready vanilla js 
Javascript :: vue watch 
Javascript :: jquery get id of 3rd parent 
Javascript :: summer note empty 
Javascript :: Replacing String Content 
Javascript :: express cors policy 
Javascript :: react update version 
Javascript :: how calculate number of digits of number 
Javascript :: image downloader extension in nodejs 
Javascript :: regex more than one character 
Javascript :: js email validation 
Javascript :: how to check alphabet case in javascript 
Javascript :: How to get maximum value in Javascript 
Javascript :: javascript object declaration 
Javascript :: × Error: Invariant failed: You should not use <Switch outside a <Router 
Javascript :: reactjs wait for image to load from url 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =