loop() {
let tree = {
'partOneLine': ['110', '242', '142'],
'partOneDict': ['42420', '42442', '42424'],
'resource': 'jlfdlj'
}
let list = {
arr: []
};
let objProps = [] // 存放对象属性的数组
for (const prop in tree) {
if(typeof tree[prop] === 'string'){
list[prop] = tree[prop];
} else if(Array.isArray(tree[prop])){
objProps.push(prop)
}
}
if (objProps[0]) {
let length = tree[objProps[0]].length
for (let i = 0; i< length; i++) {
let obj = {}
objProps.forEach((item) => {
obj[item] = tree[item][i]
})
list.arr.push(obj)
}
}
console.log(list, 'list')
},
自测能用
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…