Created
May 13, 2020 21:24
-
-
Save iceener/c9c54e8a00edf058e81df2f2418625e4 to your computer and use it in GitHub Desktop.
This file contains 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
// CSV to JSON | |
const CSVToJSON = (data, delimiter = ',') => { | |
const titles = data.slice(0, data.indexOf('\n')).split(delimiter); | |
return data | |
.slice(data.indexOf('\n') + 1) | |
.split('\n') | |
.map(v => { | |
const values = v.split(delimiter); | |
return titles.reduce((obj, title, index) => ((obj[title] = values[index]), obj), {}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment