I need help figuring out how to save the output from my array. I have tried appending the output to a csv, but this gives me an empty csv or a csv appended with the words [object] for each item in the array.
Here is a sample of the output in my array:
{
date: '2014-01-25',
firstBoxerRating: [Array],
firstBoxerWeight: 235.5,
judges: [Array],
links: [Object],
location: 'Golden Nugget Casino, Atlantic City',
metadata: '<a href="/en/judge/401833">Joseph Pasquale</a> 75-77 | <a href="/en/judge/401066">Tony Perez</a> 78-74 | <a href="/en/judge/401734">Barbara Perez</a> 78-74\n' +
'<br>',
numberOfRounds: [Array],
outcome: 'win',
rating: 20,
referee: [Object],
result: [Array],
secondBoxer: [Object],
secondBoxerLast6: [Array],
secondBoxerRating: [Array],
secondBoxerRecord: [Object],
secondBoxerWeight: 236.5,
titles: []
},
{
date: '2014-05-16',
firstBoxerRating: [Array],
firstBoxerWeight: 240.75,
judges: [Array],
links: [Object],
location: '2300 Arena, Philadelphia',
metadata: '<a href="/en/judge/402009">Pierre Benoist</a> 79-73 | <a href="/en/judge/401245">Lynne Carter</a> 78-74 | <a href="/en/judge/677642">Eric Dali</a> 79-73\n' +
'<br>',
numberOfRounds: [Array],
outcome: 'win',
rating: 20,
referee: [Object],
result: [Array],
secondBoxer: [Object],
secondBoxerLast6: [Array],
secondBoxerRating: [Array],
secondBoxerRecord: [Object],
secondBoxerWeight: 238,
titles: []
},
{
date: '2014-08-02',
firstBoxerRating: [Array],
firstBoxerWeight: 236.5,
judges: [Array],
links: [Object],
location: 'Revel Resort, Atlantic City',
metadata: ' time: 1:48\n' +
' | <a href="/en/judge/401683">Lindsey Page</a>\n' +
'<br>Williams down three times\n' +
'<br>',
numberOfRounds: [Array],
outcome: 'win',
rating: 20,
referee: [Object],
result: [Array],
secondBoxer: [Object],
secondBoxerLast6: [Array],
secondBoxerRating: [Array],
secondBoxerRecord: [Object],
secondBoxerWeight: 233,
titles: []
},
{
date: '2014-09-19',
firstBoxerRating: [Array],
firstBoxerWeight: 237,
judges: [Array],
links: [Object],
location: "Harrah's Philadelphia, Chester",
metadata: ' time: 1:34\n' +
' | <span>referee:</span> <a href="/en/referee/401364">Benjy Esteves Jr</a><span> | </span><a href="/en/judge/401043">Bernard Bruni</a> | <a href="/en/judge/400983">Larry Hazzard Jr</a> | <a href="/en/judge/402781">Alan Rubenstein</a>\n' +
'<br>',
numberOfRounds: [Array],
outcome: 'win',
rating: 20,
referee: [Object],
result: [Array],
secondBoxer: [Object],
secondBoxerLast6: [Array],
secondBoxerRating: [Array],
secondBoxerRecord: [Object],
secondBoxerWeight: 288,
titles: []
},
{
date: '2014-11-14',
firstBoxerRating: [Array],
firstBoxerWeight: 244,
judges: [Array],
links: [Object],
location: "Harrah's Philadelphia, Chester",
metadata: ' time: 2:28\n' +
' | <span>referee:</span> <a href="/en/referee/401364">Benjy Esteves Jr</a><span> | </span><a href="/en/judge/677642">Eric Dali</a> | <a href="/en/judge/400983">Larry Hazzard Jr</a> | <a href="/en/judge/671032">Mike Somma</a>\n' +
'<br>',
numberOfRounds: [Array],
outcome: 'win',
rating: 40,
referee: [Object],
result: [Array],
secondBoxer: [Object],
secondBoxerLast6: [Array],
secondBoxerRating: [Array],
secondBoxerRecord: [Object],
secondBoxerWeight: 209,
titles: []
},
I am assuming that this output is a JSON object.
This is the code I used to produce this output:
async function writeData() {
const csv = require('csv-parser')
const results = [];
fs.createReadStream('C:\\Users\\User\\Documents\\testingclean.csv')
.pipe(csv())
.on('data',(data)=> results.push(data))
.on('end', async () => {
const cookieJar = await getCookieJar();
const promises = [];
results.forEach((data) => {
promises.push(boxrec.getPersonById(cookieJar,data.id));
})
const fighters = await Promise.all(promises); // Fighters is an array
fighters.forEach((fighter) => {
console.log(fighter.output);
})
});
};
try {
writeData();
} catch (error) {
console.log("Error in writeData: " + error);
}