Is it possible to write data to file using only JavaScript?

后端 未结 10 1306
梦如初夏
梦如初夏 2020-11-21 15:45

I want to Write Data to existing file using JavaScript. I don\'t want to print it on console. I want to Actually Write data to abc.txt. I read many answered que

10条回答
  •  离开以前
    2020-11-21 16:00

    const data = {name: 'Ronn', age: 27};              //sample json
    const a = document.createElement('a');
    const blob = new Blob([JSON.stringify(data)]);
    a.href = URL.createObjectURL(blob);
    a.download = 'sample-profile';                     //filename to download
    a.click();
    

    Check Blob documentation here - Blob MDN to provide extra parameters for file type. By default it will make .txt file

提交回复
热议问题