你好,朋友们,假设我下面有嵌套的数据
const payload = [
{
title: "ADDITIONAL",
data: [
{
documentCategory: "ADDITIONAL",
documentCode: "CUSTOMER_CLAIM_FORM",
documentKey:
"customer/9fdf7ca8-4251-41c8-9116-6d006fa64aea/800123000004054/LIFESAVER_DEATH/LIFESAVER_DEATH_CUSTOMER_CLAIM_FORM_ca2b0204-b8c4-42f7-b059-580818789a64.jpg"
},
{
documentCategory: "ADDITIONAL",
documentCode: "POWER_OF_ATTORNEY",
documentKey:
"customer/9fdf7ca8-4251-41c8-9116-6d006fa64aea/800123000004054/LIFESAVER_DEATH/LIFESAVER_DEATH_POWER_OF_ATTORNEY_6de88371-c666-4ce5-87f2-8aedf778f4c4.jpg"
},
{
documentCategory: "ADDITIONAL",
documentCode: "POLICE_RECORD",
documentKey:
"customer/9fdf7ca8-4251-41c8-9116-6d006fa64aea/800123000004054/LIFESAVER_DEATH/LIFESAVER_DEATH_POLICE_RECORD_15d989de-9cfb-4574-8451-92f445177331.jpg"
}
],
chevronFlag: true
},
...
]
我试过下面几种方法
for (let i = 0; i < payload.length; i++) {
const element = payload[i].data.map((item) => {
return item;
});
console.log(element);
}
我得到了数组中每个属性的每个新对象的结果
enter image description here
我的目标是
const newObj = {
documentCode: "CUSTOMER_CLAIM_FORM"
documentKey: "customer/9fdf7ca8-4251-41c8-9116-6d006fa64aea/800123000004054/LIFESAVER_DEATH/LIFESAVER_DEATH_CUSTOMER_CLAIM_FORM_ca2b0204-b8c4-42f7-b059-580818789a64.jpg",
documentCode: "POWER_OF_ATTORNEY"
documentKey: "customer/9fdf7ca8-4251-41c8-9116-6d006fa64aea/800123000004054/LIFESAVER_DEATH/LIFESAVER_DEATH_POWER_OF_ATTORNEY_6de88371-c666-4ce5-87f2-8aedf778f4c4.jpg",
...
}
请帮助我理解...非常感谢
2条答案
按热度按时间5w9g7ksd1#
对象内部只能有唯一键。使用
documentCode
值作为属性键怎么样?答复:
bzzcjhmw2#
如果我正确地理解了你的问题,那么你所需要做的就是以下面的格式得到答案:
该数组已用作对象数据的父 Package 器,因为您的有效负载是一个数组,并且它将具有更多包含数据的对象。
解决方案
答复
随着您的响应增长,它会不断添加更多的数据,您将看到数据变化时的变化。