📜  解析 csv javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:18.952000             🧑  作者: Mango

代码示例1
//Suppose you have a CSV file data.csv which contains the data:

//NAME,AGE
//Daffy Duck,24
//Bugs Bunny,22

const csv = require('csv-parser')
const fs = require('fs')
const results = []; 

fs.createReadStream('data.csv')
  .pipe(csv())
  .on('data', (data) => results.push(data))
  .on('end', () => console.log(results));

 // [{ NAME: 'Daffy Duck', AGE: '24' },
//   { NAME: 'Bugs Bunny', AGE: '22' } ]