0

Trying to console.log() a row of data read in with papaparse but I'm just getting an array of [object Object]. How do I console.log the row of unwrapped values?

var fs = require('fs');
eval(fs.read('papaparse.min.js'));

var config = {
    delimiter: "",  // auto-detect
    newline: "",    // auto-detect
    header: true,
    dynamicTyping: false,
    preview: 0,
    encoding: "utf-8",
    worker: false,
    comments: false,
    step: undefined,
    complete: undefined,
    error: undefined,
    download: false,
    skipEmptyLines: true,
    chunk: undefined,
    fastMode: undefined
};

var file = Papa.parse(fs.read('some_file.csv'), config);

for (var row in file.data) {
    // this prints [object Object],[object Object], etc
    console.log(file.data);

    // How do I get
    // value, value, value, value, etc

}
ProGirlXOXO
  • 2,170
  • 6
  • 25
  • 47

1 Answers1

2

Per the Papa Parse result docs :

data is an array of rows. If header is false, rows are arrays; otherwise they are objects of data keyed by the field name.

Also you are trying to log the whole array in each iteration. It is best not to use for in for arrays

Try

file.data.forEach(function(row){
    console.log(JSON.stringify(row));
});
charlietfl
  • 170,828
  • 13
  • 121
  • 150