我有一个回调函数,在打印row
时,会得到以下控制台输出
。
output of row [ 'Name', 'Language' ]
output of row [ 'English', 'Fr' ]
output of row [ 'German', 'Gr' ]
output of row [ 'France', 'London' ]
我希望将上述数组转换为有效的JSON,但排除第一行,结果如下。
{
"English" : "Fr",
"German" : "Gr",
"France" : "London"
}
.on('record', function(row, index){
console.log("output of row", row);
var obj = {};
row.forEach(function(column, index) {
obj[row[index].trim()] = row[index].trim();
})
record.push(obj);
}
})
额外的代码
我正在获取CSV数据,每次将其推入一行。以下是CSV数据和每次读取CSV数据时获取的数组...
Language,Name
Fr,English
Gr,German
London,France
output of row [ 'Name', 'Language' ]
output of row [ 'English', 'Fr' ]
output of row [ 'German', 'Gr' ]
output of row [ 'France', 'London' ]
cvcsv()
.from.string(csv)
.transform( function(row){
row.unshift(row.pop());
return row;
})
.on('record', function(row, index){
console.log("output of row",row)