You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Logs the content of the object at the specified key. EG:
console.log(row['siteName'] )
would log "Your site" or "My site"
Actual Behavior
Doesn't extract the value of the object at the given key. The value at the column "siteName" can only be extracted using Object.keys(row)[0] 0 being the index of the first column.
How Do We Reproduce?
Here is the data
siteName
July
August
Your site
323
444
My site
111
222
const fs = require('fs');
const csv = require('csv-parser');
const file1 = './data.csv';
let totalGenerationData = {};
// Function to read CSV and extract the column data based on siteName
function readCSV(filePath, columnName, dataObject, callback) {
fs.createReadStream(filePath)
.pipe(csv())
.on('data', (row) => {
// As expected logs :
// { 'siteName': 'My site', July: '28926', August: '37746' }
// { 'siteName': 'Your site', July: '7107', August: '9352' }
console.log(row)
//As expected logs "siteName" "siteName"
console.log(Object.keys(row)[0])
// Logs undefined undefined
console.log(row['siteName'])
// Logs "My site"
// Logs "Your site"
console.log(row[Object.keys(row)[0]])
})
}
// Read both files and compare the data
readCSV(file1, '', totalGenerationData, () => { });
Interestingly the bug cannot be reproduced if siteName is the last column of the csv file.
The text was updated successfully, but these errors were encountered:
Did you check that your file does not contain invisible characters in the header line? Try hexdump -C data.csv. Typical candidate migth be a BOM which adds 3 invisible chars at the beginning of the file.
Expected Behavior
Logs the content of the object at the specified key. EG:
console.log(row['siteName'] )
would log "Your site" or "My site"
Actual Behavior
Doesn't extract the value of the object at the given key. The value at the column "siteName" can only be extracted using
Object.keys(row)[0]
0 being the index of the first column.How Do We Reproduce?
Here is the data
Interestingly the bug cannot be reproduced if siteName is the last column of the csv file.
The text was updated successfully, but these errors were encountered: