CSV Download from Javascript

CSV Download example from javascript.

JavaScript

var data = [["name1", "city1", "some other info"], ["name2", "city2", "more info"]];
/* const data = [["2018-10-05 08:23:38","Hoofdtoegang","Acces granted","Mr Ronny Pape"],["2018-10-05 01:27:10","Hoofdtoegang","Acces granted","Mr Daan Pape"],["2018-10-04 23:29:20","Hoofdtoegang","Acces granted","Mr Daan Pape"],["2018-10-03 23:25:03","Hoofdtoegang","Acces granted","Mr Daan Pape"],["2018-10-03 21:23:53","Hoofdtoegang","Acces granted","Ms Julie Robays"],["2018-10-03 08:38:55","Hoofdtoegang","Acces granted","Mr Ronny Pape"],["2018-10-02 22:37:10","Hoofdtoegang","Acces granted","Ms Julie Robays"],["2018-10-02 22:31:21","Hoofdtoegang","Acces granted","Mr Daan Pape"],["2018-10-01 19:56:24","Hoofdtoegang","Acces granted","Ms Julie Robays"],["2018-10-01 19:34:58","Hoofdtoegang","Acces granted","Ms Julie Robays"]] */
var csvContent = "data:text/csv;charset=utf-8,";
data.forEach(function(infoArray, index){

   dataString = infoArray.join(",");
   csvContent += index < infoArray.length ? dataString+ "\n" : dataString;

}); 

var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "my_data.csv");

link.click();