Created
February 5, 2022 13:15
-
-
Save neysidev/7b39a9da313cfb0ed0928e34a07eedc4 to your computer and use it in GitHub Desktop.
Convert array to csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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