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 :: javscript loop array 
Javascript :: concat no and string in javascript 
Javascript :: jest write test for function 
Javascript :: get array by array of indices js 
Javascript :: make image onclick in vuejs 
Javascript :: nodejs get cpu count 
Javascript :: exclude vales from array in js 
Javascript :: change value on selected jquery 
Javascript :: react without using jsx create element 
Javascript :: send response from iframe to parent 
Javascript :: how fetch multiple data in javascript react 
Javascript :: two days before in moment 
Javascript :: react router params and render 
Javascript :: computed property names 
Javascript :: how to draw circle in javascript 
Javascript :: download file from api response 
Javascript :: javascript log where function was called 
Javascript :: electronjs 
Javascript :: vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in nextTick: "RangeError: Maximum call stack size exceeded" 
Javascript :: padend javascript 
Javascript :: javascript strings are immutable 
Javascript :: create canvas p5 
Javascript :: faire un tableau en javascript 
Javascript :: what is syntactic sugar javascript 
Javascript :: jq break line 
Javascript :: multiple checkbox validation in javascript 
Javascript :: redux action creators 
Javascript :: json in python 
Javascript :: what is event loop in javascript 
Javascript :: react s3 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =