如何循环遍历以下形式的嵌套对象:{'AAA':{oldName:{index:0,first:'Bob',last:'Hanson'},newName:{index:0,first:'Bob',last:'Hanson'}},'BBB':{
如何循环遍历表单的嵌套对象
{
'AAA':
{ oldName: { index: 0, first: 'Bob', last: 'Hanson' },
newName: { index: 0, first: 'Bob', last: 'Hanson' }
},
'BBB':
{ oldName: { index: 1, first: 'Velma', last: 'Jones' },
newName: { index: 2, first: 'Velma', last: 'Roberts'}
},
'CCC':
{ oldName: { index: 2, first: 'Jou', last: 'Xi' },
newName: { index: 3, first: 'Jou', last: 'Xi' }
},
'DDD':
{ oldName: { index: 3, first: 'Betty', last: 'Ford' },
newName: undefined},
'EEE':
{ oldName: undefined,
newName: { index: 1, first: 'Fred', last: 'Tree' }
}
}
并删除所有嵌套对象,其中对于每个第一级键, AAA, BBB, CCC, DDD, EEE
键 oldName 的值 = 键 newName 的值
因此,我最终
{
'BBB':
{ oldName: { index: 1, first: 'Velma', last: 'Jones' },
newName: { index: 2, first: 'Velma', last: 'Roberts' }
},
'DDD':
{ oldName: { index: 3, first: 'Betty', last: 'Ford' },
newName: undefined },
'EEE':
{ oldName: undefined,
newName: { index: 1, first: 'Fred', last: 'Tree' }
}
}