let a=[{"a":12,b:{"d":23}},{"a":912,b:{"d":923}}]
let res = [{}]
for (var index = 0; index < a.length; index += 1) {
Object.keys(a[index]).forEach(key => {
if (typeof a[index][key] === "object") {
Object.keys(a[index][key]).forEach(
innerKey => {res[index][innerKey] = a[index][key][innerKey]}
)
}else{
console.log(a[index][key])
res[index][key] = a[index][key]
console.log(res)
}
})
}
请问我想把a展平,为什么上面那样写数组的第一个对象出来了,可是第二个出错了。谢谢
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…