【原数组】
data: Array(5)
0: ["ID", "姓名", "电话", "地址", "邮箱", "工号"],
1: ["1", "小王", "11111", "北京", "11111@qq.com", "g1"],
2: ["2", "小李", "22222", "北京", "22222@qq.com", "g2"],
3: ["3", "小赵", "33333", "北京", "33333@qq.com", "g3"],
4: ["4", "小张", "44444", "北京", "44444@qq.com", "g4"]
【如何遍历成以下的新数组】
data: Array(5)
0: ["ID":1,"姓名":"小王", "电话":"11111", "地址":"北京", "邮箱":"11111@qq.com", "工号":"g1"],
1: ["ID":2,"姓名":"小李", "电话":"22222", "地址":"北京", "邮箱":"22222@qq.com", "工号":"g2"],
2: ["ID":3,"姓名":"小赵", "电话":"33333", "地址":"北京", "邮箱":"33333@qq.com", "工号":"g3"],
3: ["ID":4,"姓名":"小张", "电话":"44444", "地址":"北京", "邮箱":"44444@qq.com", "工号":"g4"],
https://developers.weixin.qq.com/s/dujR2wmf7Zj2
请学会如何「提问」(👈戳我)、【个体工商户】微信认证问题(👈戳我)
新数组的元素应该是对象才对吧:
{"ID":1,"姓名":"小王", "电话":"11111", "地址":"北京", "邮箱":"11111@qq.com", "工号":"g1"}
let keyArr = Array.shift();
let newArray = [];
Array.forEach((item)=>{
let _opt = {};
item.forEach((jitem, jindex)=>{
opt[keyArr[jindex]] = jitem;
});
newArray.push(_opt)
});
console.log(newArray)
可以直接贴你接口请求返回的列表吗?