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

前端 未结 29 2113
没有蜡笔的小新
没有蜡笔的小新 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

    One arrow function with ES6 :

    const dataToCsvURI = (data) => encodeURI(
    `data:text/csv;charset=utf-8,${data.map((row, index) =>  row.join(',')).join(`\n`)}`
    );
    

    Then :

    window.open(
      dataToCsvURI(
       [["name1", "city_name1"/*, ...*/], ["name2", "city_name2"/*, ...*/]]
      )
    );
    

    In case anyone needs this for reactjs, react-csv is there for that

提交回复
热议问题