最近负责的项目在写对本地JSON 文件和 CSV文件实现预览,解析,上传到分析平台的功能.处理过程中遇到了一些数据的处理问题,比如说要整合新的对象.然后就通过自己写的,抽出来记录一下.
目的:将 CSV文件数据预览到页面的表格中:
想法:将 CSV的第一行读取出来,作为 header,之后的行的内容根据 header的字段去一一对应显示.
页面截图:

代码抽象:
var a = ['name', 'pwd', 'age', 'address'];
var c =[
['张三','123456',15,'sichuan'],
['李四','123456',15,'山西'],
['张三','123456',15,'sichuan'],
['李四','123456',15,'山西']
];
--------->
想得到

var whole = [];
c.map((item,index) => {
let json = {};
item.map((item, index) => {
json[a[index]] = item;
})
whole.push(json);
})
console.log('whole',whole);[如截图~~~]
网友评论