I am trying to read csv in typescript column by column.
The csv is like below:
Prefix,Suffix
Mr,Jr
Mrs,Sr
Based on few SO questions and typescript documentation, I am able to read from file like:
public readConfig() {
const results: any[] = [];
fs.createReadStream('D:/NameConfig.csv')
.pipe(csv())
.on('data', (data: any) => results.push(data))
.on('end', () => {
return results;
});
}
But, this reads the entire csv. I am unable to save the individual columns like Prefix and Suffix as individual array. How can I achieve the same?