Created
October 9, 2018 21:24
-
-
Save jtara1/b708a4ed0e1ca873c89e5f593f7874b9 to your computer and use it in GitHub Desktop.
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
const fs = require('fs'); | |
function toCsv(arrayOfObjects) { | |
let getProps = (object) => { | |
return Object.getOwnPropertyNames(object); | |
}; | |
let props = getProps(arrayOfObjects[0]); | |
let outputString = props.join(',') + '\n'; | |
for (let object of arrayOfObjects) { | |
let values = Object.values(object).join(','); | |
outputString += values + '\n'; | |
console.log(JSON.stringify(values)); | |
} | |
console.log(); | |
fs.writeFile('Danijel-tx.csv', outputString, err => { if (err) logger.error(err) }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment