Write CSV file column title in javascript

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Write CSV file column title in javascript



This is my code. I am trying to output my data as CSV and I am being successful but I can't add the title of the columns. Although I saved the CSV file but the column titles are missing. Can anyone help in this?


var d= new Date();
var t=d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
var data = dataAWS
var result = data.map(function(val)
return t+'","'+val.payload.test_data;
).join('"n"');
var csvData = '"'+ result +'"';

var fs = require('fs');
fs.writeFile("tempN.csv", csvData, 'utf8', function (err)
if (err)
console.log("An error occured while saving CSV.");
return console.log(err);


console.log("CSV file has been saved.");
);




1 Answer
1



Without knowing more I would suggest something like:


data.unshift(column_headers);
var result = data.map(function(val)
return t+'","'+val.payload.test_data;
).join("n")
etc, etc





I had done that. It will just make two columns without title. So, I found a better way. I created a CSV file with two columns first, and then used append to put the column values.
– Sajid Baloch
Aug 27 at 15:01






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard