javascript - 如何将 csv 文件转换为节点中的对象?
问题描述
我一直在尝试使用 nodejs 包'csvtojson',我可以返回数据的控制台日志,但我似乎无法弄清楚如何将它存储在变量/对象中。npmjs.com和GitHub 页面上的文档非常简短,只展示了一种使用方式。
稍后我试图在我的 js 文件中对这些数据做更多的事情,所以我需要它在一个对象中。
到目前为止,我有:
const convertCsv = require('csvtojson').Converter;
const csv = new convertCsv;
const filePath = (relative path to file);
csv.fromFile(filePath).then((jsonObj)=>{
//this is working
console.log(jsonObj);
})
let kO = csv.fromFile(filePath);
//this is not
console.log(kO);
解决方案
推荐阅读
- angular - 对于嵌套的 for 循环,角度虚拟滚动无法正常工作
- javascript - 异步等待 API 调用后 Reactjs 状态不更新
- javascript - Angular 单元测试验证子组件的方法调用
- reactjs - reactjs中的元素类型无效
- javascript - PdfMake getBase64 undefined - React JS
- python-3.x - 在 aws CodePipelines 上工作,堆栈创建每次都失败
- java - Android Studio:有没有办法更改 ArrayAdapter 上显示的文本?
- vba - VBA根据单元格值打印多张纸
- javascript - 反应:停止重新渲染状态变化的部分
- arrays - 失去对分配数组的引用 - 下标超出范围