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
Here's a solution similar to mightybruno's answer that handles strings containing commas. None of the other answers seem to take this in to consideration.
function objectsToCSV(arr) {
const array = [Object.keys(arr[0])].concat(arr)
return array.map(row => {
return Object.values(row).map(value => {
return typeof value === 'string' ? JSON.stringify(value) : value
}).toString()
}).join('\n')
}