【发布时间】:2020-05-03 10:47:22
【问题描述】:
我给了一个嵌套对象数组,我想将它转换成一个简单的对象数组,我不知道如何解决这个问题,谁能给我一个解决这个问题的方法。我试过但是我自己无法解决或者我没有找到类似的东西
const data = [
{
attachment: {
Name: {type: string, value: 'Amar'},
'Second Contact': {type: 'phoneNumber', value: '+91123587900'},
'First Contact': {type: 'phoneNumber', value: '+911234567890'},
'Registered Office Address': {
value: 'New Delhi',
type: 'string',
},
'Company Logo': {type: 'string', value: ''},
'Youtube ID': {type: 'string', value: ''},
},
creator: {
displayName: 'xyz',
phoneNumber: '+915453553554',
photoURL:
'https://www.google.com/url?sa=i&source=images&cd=&ved=2ahUKEwixw9uJrYjnAhWOe30KHa42AFwQjRx6BAgBEAQ&url=https%3A%2F%2Funsplash.com%2Fs%2Fphotos%2Fpic&psig=AOvVaw24C_LUOadGZAi3r2JtZe9b&ust=1579272070036146',
},
},
{
attachment: {
Name: {type: string, value: 'hari'},
'Second Contact': {type: 'phoneNumber', value: '+91153587900'},
'First Contact': {type: 'phoneNumber', value: '+911264567890'},
'Registered Office Address': {
value: 'New Delhi mv',
type: 'string',
},
'Company Logo': {type: 'string', value: ''},
'Youtube ID': {type: 'string', value: ''},
},
creator: {
displayName: 'xyz',
phoneNumber: '+915453543554',
photoURL:
'https://www.google.com/url?sa=i&source=images&cd=&ved=2ahUKEwixw9uJrYjnAhWOe30KHa42AFwQjRx6BAgBEAQ&url=https%3A%2F%2Funsplash.com%2Fs%2Fphotos%2Fpic&psig=AOvVaw24C_LUOadGZAi3r2JtZe9b&ust=1579272070036146',
},
},
];
预期的输出是这样的
[
{
Name:'Amar',
'Second Contact':+91123587900,
'First Contact':+911234567890,
'Registered Office Address':'New Delhi',
displayName:'xyz',
phoneNumber:'+915453553554'
},
{
Name:'hari',
'Second Contact':+91153587900,
'First Contact':+911264567890,
'Registered Office Address':'New Delhi mv',
displayName:'xyz',
phoneNumber:'+915453543554'
}
]
【问题讨论】:
-
它只是一个特定的案例还是你想要通用的方式来做到这一点?
-
@miyavmiyav 以通用方式进行操作
-
请先发布您的解决方案。你试图解决这个问题的方法
标签: javascript arrays javascript-objects nested-object