gpt4 book ai didi

javascript - 如何跳过 CSV 中的第一行项目?

转载 作者:行者123 更新时间:2023-11-30 21:07:41 25 4
gpt4 key购买 nike

我试图在以下函数中跳过 CSV 中项目的第一行或标题:

importFoods() {
var csv= `foodname,category
Banana,Produce
Apple,Produce`;

var lines = csv.split("\n");
console.log('lines',lines);
for(var l in lines) {
var cols = lines[l].split(",")
console.log('cols',cols);
//0 is foodname
//1 is category
var globallistData = {
foodname: cols[0],
category: cols[1],
};

console.log(globallistData)
const globalfoods = this.db.list('/globalfoods');
globalfoods.push(globallistData);
}
}

使用 Angular 或 Typescript/Javascript 执行此操作的最佳方法是什么?

最佳答案

importFoods(){
var csv= `foodname,category
Banana,Produce
Apple,Produce`;

var lines = csv.split("\n");
console.log('lines',lines);
for(var l=1; l<lines.length ;l++){
var cols = lines[l].split(",")
console.log('cols',cols);
//0 is foodname
//1 is category
....
}
}

关于javascript - 如何跳过 CSV 中的第一行项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46459066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com