let list = [
["预付款项", "支付现金", "长期借款"],
[755340403, 17085162670, 3536364338],
[1204418576, 8658473101, 3444301912],
]
let header = ['公司', '2020-12-31', '2021-06-30']
怎么把list和header两个数组是实现TableData这个效果呢
let TableData = [
{'公司':'预付款项', '2020-12-31': 755340403, '2021-06-30': 1204418576},
{'公司':'支付现金', '2020-12-31': 17085162670, '2021-06-30': 8658473101},
{'公司':'长期借款', '2020-12-31': 3536364338, '2021-06-30': 3444301912},
]
按照你的要求编写的程序如下
let list = [
["预付款项", "支付现金", "长期借款"],
[755340403, 17085162670, 3536364338],
[1204418576, 8658473101, 3444301912],
]
let header = ['公司', '2020-12-31', '2021-06-30']
let TableData =[]
for(let i=0;i<list.length;i++){
let temp={}
for(let j=0;j<list[i].length;j++){
temp[header[j]]=list[j][i]
}
TableData.push(temp)
}
document.write(JSON.stringify(TableData))
代码:
let list = [
["预付款项", "支付现金", "长期借款"],
[755340403, 17085162670, 3536364338],
[1204418576, 8658473101, 3444301912],
];
let header = ['公司', '2020-12-31', '2021-06-30'];
let TableData = [];
for(let i = 0; i < list[0].length; i++)
{
TableData[i] = {};
for(let j = 0; j < header.length; j++)
TableData[i][header[j]] = list[j][i];
}
console.log(TableData);
运行结果: