JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<button onclick="exportToCsv()">export to CSV</button>
</div>
JavaScript
var items = [
{
title: 'title1',
youtube: 'youtubevideoid',
audioaddress: "audio1.mp3",
year: '2022',
month: '07',
day: '22',
time: 'AM',
speaker: 'speaker1'
},
{
title: 'title2',
youtube: 'youtubevideoid2',
audioaddress: "audio2.mp3",
year: '2022',
month: '07',
day: '22',
time: 'PM',
speaker: 'speaker2'
},
];
var itemsgrouped = [
];
for(var i = 0; i < items.length; i++){
itemsgrouped.push(
[
items[i].title,
items[i].youtube,
items[i].audioaddress,
items[i].year,
items[i].month,
items[i].day,
items[i].time,
items[i].speaker
]
)
}
//Download CSV of Javascript Array
exportToCsv = function() {
var CsvString = "";
itemsgrouped.forEach(function(RowItem, RowIndex) {
RowItem.forEach(function(ColItem, ColIndex) {
CsvString += ColItem + ',';
});
CsvString += "\r\n";
});
CsvString = "data:application/csv," + encodeURIComponent(CsvString);
var x = document.createElement("A");
x.setAttribute("href", CsvString );
x.setAttribute("download","itemsgrouped.csv");
document.body.appendChild(x);
x.click();
}