How to export JavaScript array info to csv (on client side)?

前端 未结 29 1678
没有蜡笔的小新
没有蜡笔的小新 2020-11-21 21:55

I know there are lot of questions of this nature but I need to do this using JavaScript. I am using Dojo 1.8 and have all the attribute info in array, which loo

29条回答
  •  情歌与酒
    2020-11-21 22:47

    Old question with many good answers, but here is another simple option that relies on two popular libraries to get it done. Some answers mention Papa Parse but roll their own solution for the download part. Combining Papa Parse and FileSaver.js, you can try the following:

    const dataString = Papa.unparse(data, config);
    const blob = new Blob([dataString], { type: 'text/csv;charset=utf-8' });
    FileSaver.saveAs(blob, 'myfile.csv');
    

    The config options for unparse are described here.

提交回复
热议问题