JS数组转换的操作方法?

如何把这种数据
image.png
转换成

image.png

这是自己写的
image.png
,结果
image.png

阅读 1.7k
2 个回答
✓ 已被采纳

let data = {
    listA: ['A1','A2','A3','A4','A5','A6','A7','A8','A9'],
    listB: ['B1',"B2","B3",'B4',"B5","B6","B7","B8","B9"],
    listC: ['C1',"C2","C3",'C4',"C5","C6","C7","C8","C9"]
}
let result = Object.keys(data).reduce((p,key)=>{
    for(let i = 0;i<data[key].length;i++){
        p[i] ? p[i].data.push(data[key][i]) : p[i] = {data:[data[key][i]]}
    }
    return p;
},[])
let data = {
listA: ['A1','A2','A3','A4','A5','A6','A7','A8','A9'],
listB: ['B1',"B2","B3",'B4',"B5","B6","B7","B8","B9"],
listC: ['C1',"C2","C3",'C4',"C5","C6","C7","C8","C9"]
}
let result = data.listA.map((v, i) => ({data: Object.entries(data).map(it => it[1][i])}))



撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题