let csv = require('fast-csv');
let fs = require('fs');
let readFileStream = fs.createReadStream(csvPath).setEncoding('utf-8');
let insList = [];
csv
.fromStream(readStream, {headers: true})
.on('data', function (data) {
if (data[1] !== '' && insList.indexOf(data[1]) === -1 )
insList.push(data[1]);
})
.on('end', function () {
console.log(insList);
console.log('done');
})
The console.log(instList) line gives undefined when the {headers:true} is passed as argument to csv.fromStream. Why does that happen and how can I solve it?
If {headers:true} is not passed as argument the insList array gives the column name and all other unique elements in that column.
I want the insList array to hold all unique items of column 1 (i.e. data[1]).