/**
* 需求:
* {
msg: [
{
"one": [
["seq","0001"]
],
"two": [
[
"key1","GFC001",1630398105171
],
[
"key2","20",1630398105171
],
[
"key3","xiaolan",1630398105171
],
]
},
{
"one": [
["seq","0002"]
],
"two": [
[
"key1","GFC002",16308105171
],
[
"key2","18",163039810571
],
[
"key3","xiaoxiao",1638105171
],
]
},
{
"one": [
["seq","0003"]
],
"two": [
[
"key1","GFC003",105171
],
[
"key2","15",1630398171
],
[
"key3","xiaohua",1635171
],
]
}
]
}
*改为
*[
* {key1: 'GFC001', key2: '20', key3: 'xiaolan', seq: '0001'},
* {key1: 'GFC002', key2: '18', key3: 'xiaoming', seq: '0002'},
* {key1: 'GFC013', key2: '19', key3: 'lihua', seq: '0003'}
*]
*
*/
var arrayList = {
msg: [
{
"one": [
["seq","0001"]
],
"two": [
[
"key1","GFC001",1630398105171
],
[
"key2","20",1630398105171
],
[
"key3","xiaolan",1630398105171
],
]
},
{
"one": [
["seq","0002"]
],
"two": [
[
"key1","GFC002",16308105171
],
[
"key2","18",163039810571
],
[
"key3","xiaoxiao",1638105171
],
]
},
{
"one": [
["seq","0003"]
],
"two": [
[
"key1","GFC003",105171
],
[
"key2","15",1630398171
],
[
"key3","xiaohua",1635171
],
]
}
]
}
// 数据整合
const transformData = (dataArray) => {
let listArray = []
let msg = dataArray.msg || [];
for (let i of msg) {
//console.log("i-----",i)
let obj = {}
for (let j of i.two) {
//console.log("j--------",j)//['key1', 'GFC013', 1630398105342]
obj[j[0]] = j[1]
}
for (let k of i.one) {
//console.log("k--------",k)//['seq', '0003']
obj[k[0]] = k[1]
}
listArray.push(obj)
}
return listArray
}
console.log(transformData(arrayList))