11
test/JSONtoCSV/JSONtoCSV.js
Normal file
11
test/JSONtoCSV/JSONtoCSV.js
Normal file
@ -0,0 +1,11 @@
|
||||
const JSONtoCSV = (arr, columns, delimiter = ',') =>
|
||||
[
|
||||
columns.join(delimiter),
|
||||
...arr.map(obj =>
|
||||
columns.reduce(
|
||||
(acc, key) => `${acc}${!acc.length ? '' : delimiter}"${!obj[key] ? '' : obj[key]}"`,
|
||||
''
|
||||
)
|
||||
)
|
||||
].join('\n');
|
||||
module.exports = JSONtoCSV;
|
||||
Reference in New Issue
Block a user