I am trying to convert a JavaScript object set in to CSV format
You can get the idea about my Javascript object, if you put it in online JSON parser http://json.pars
Similar to mightybruno's answer but this would allow separate access to the headers and content (by moving the join statements to later in the function) if desired.
function objToCsv(data) {
const headers = Object.keys(data[0]).join();
const content = data.map(r => Object.values(r).join());
return [headers].concat(content).join("\n");
}