I have array structure as shown in below
[
{
"id": "cbdfc96a-c788-45cd-bdd1-7d573cc8c474",
"refId": "1",
"reference": "<p>1646 Journal of Investigative Dermatology ( 2017 ) , Volume 137</p>",
"list": [
{
"text": "<p>Annot 1</p>",
"id": "e9c207ae-3d08-4eb2-94d1-b6ae713862d3"
},
{
"text": "<p>Annot 1</p>",
"id": "e1486639-aa46-4513-992b-17d8d66f06c8"
}
]
},
{
"id": "90b187ab-26ef-45c0-a6a0-bf7dcfde660f",
"refId": "2",
"reference": "<p>ZK Jabbar - Lopez et al . Evaluation of Biologic Therapy Options for Psoriasis</p>",
"list": [
{
"text": "<p>Annot 2</p>",
"id": "fc430895-912a-4e4b-884c-f08600e06ec8"
},
{
"text": "<p>Annot 2 3</p>",
"id": "a1296b1f-530e-4e1b-b2d0-f97bba192a1a"
},
{
"text": "<p>Annot 2 3</p>",
"id": "090737d5-48ac-4e3f-973d-9e1de206252b"
},
{
"text": "<p>Annot 2</p>",
"id": "6d5f89be-305e-4751-a7ca-75d9b0f2057e"
}
]
},
{
"id": "e8c3a958-7fa4-40e1-a83a-44c85ebb05a7",
"refId": "3",
"reference": "<p>Table 2. Relative treatment rankings ( outcomes at 12 to 16 wk )</p>",
"list": [
{
"text": "<p>Annot 3</p>",
"id": "f9082af8-3c2f-477b-b113-a96f320415d1"
},
{
"text": "<p>Annot 3</p>",
"id": "2d7e65b8-e516-40bf-8957-c0fb4b819aa9"
}
]
}
]
Expected result is
[
{
"id": "cbdfc96a-c788-45cd-bdd1-7d573cc8c474",
"refId": "1",
"reference": "<p>1646 Journal of Investigative Dermatology ( 2017 ) , Volume 137</p>",
"list": [
{
"text": "<p>Annot 1</p>",
"id": "e9c207ae-3d08-4eb2-94d1-b6ae713862d3"
}
]
},
{
"id": "90b187ab-26ef-45c0-a6a0-bf7dcfde660f",
"refId": "2",
"reference": "<p>ZK Jabbar - Lopez et al . Evaluation of Biologic Therapy Options for Psoriasis</p>",
"list": [
{
"text": "<p>Annot 2</p>",
"id": "fc430895-912a-4e4b-884c-f08600e06ec8"
},
{
"text": "<p>Annot 2 3</p>",
"id": "a1296b1f-530e-4e1b-b2d0-f97bba192a1a"
}
]
},
{
"id": "e8c3a958-7fa4-40e1-a83a-44c85ebb05a7",
"refId": "3",
"reference": "<p>Table 2. Relative treatment rankings ( outcomes at 12 to 16 wk )</p>",
"list": [
{
"text": "<p>Annot 3</p>",
"id": "f9082af8-3c2f-477b-b113-a96f320415d1"
}
]
}
]
I have tried this solution but didnot get the expected result.
const finalListmergedArray = [
{
"id": "cbdfc96a-c788-45cd-bdd1-7d573cc8c474",
"refId": "1",
"reference": "<p>1646 Journal of Investigative Dermatology ( 2017 ) , Volume 137</p>",
"list": [
{
"text": "<p>Annot 1</p>",
"id": "e9c207ae-3d08-4eb2-94d1-b6ae713862d3"
},
{
"text": "<p>Annot 1</p>",
"id": "e1486639-aa46-4513-992b-17d8d66f06c8"
}
]
},
{
"id": "90b187ab-26ef-45c0-a6a0-bf7dcfde660f",
"refId": "2",
"reference": "<p>ZK Jabbar - Lopez et al . Evaluation of Biologic Therapy Options for Psoriasis</p>",
"list": [
{
"text": "<p>Annot 2</p>",
"id": "fc430895-912a-4e4b-884c-f08600e06ec8"
},
{
"text": "<p>Annot 2 3</p>",
"id": "a1296b1f-530e-4e1b-b2d0-f97bba192a1a"
},
{
"text": "<p>Annot 2 3</p>",
"id": "090737d5-48ac-4e3f-973d-9e1de206252b"
},
{
"text": "<p>Annot 2</p>",
"id": "6d5f89be-305e-4751-a7ca-75d9b0f2057e"
}
]
},
{
"id": "e8c3a958-7fa4-40e1-a83a-44c85ebb05a7",
"refId": "3",
"reference": "<p>Table 2. Relative treatment rankings ( outcomes at 12 to 16 wk )</p>",
"list": [
{
"text": "<p>Annot 3</p>",
"id": "f9082af8-3c2f-477b-b113-a96f320415d1"
},
{
"text": "<p>Annot 3</p>",
"id": "2d7e65b8-e516-40bf-8957-c0fb4b819aa9"
}
]
}
]
// Loop through array values
for (let i = 0; i < finalListmergedArray.length; i++) {
for (
let j = 0;
j < finalListmergedArray[i]["list"].length;
j++
) {
var result = [
...new Map(
finalListmergedArray[i]["list"].map((o) => [
JSON.stringify(o),
o,
])
).values(),
];
finalListmergedArray[i]["list"] = result;
}
}
console.log(finalListmergedArray)
Any help would be appreciated. Thanks, in advance.