Skip to content

Instantly share code, notes, and snippets.

@neysidev
Created February 5, 2022 13:15
Show Gist options
  • Select an option

  • Save neysidev/7b39a9da313cfb0ed0928e34a07eedc4 to your computer and use it in GitHub Desktop.

Select an option

Save neysidev/7b39a9da313cfb0ed0928e34a07eedc4 to your computer and use it in GitHub Desktop.
Convert array to csv
function arrayToCsv(data) {
return data
.map(
row =>
row
.map(String) // convert every value to String
.map(v => v.replaceAll('"', '""')) // escape double colons
.map(v => `"${v}"`) // quote it
.join(",") // comma-separated
)
.join("\r\n") // rows starting on new lines
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment