I have this type of array in the angular 14
[
{
"parentItem": "WBP258R",
"childItem": "WBP258R",
"columnName": "Color",
"oldValue": "Rainbow",
"newValue": "Rainbow1"
},
{
"parentItem": "WBP258R",
"childItem": "WBP258R",
"columnName": "Pg #",
"oldValue": "4",
"newValue": "44"
},
{
"parentItem": "WBP258R",
"childItem": "WBP258R",
"columnName": "Status",
"oldValue": "New",
"newValue": "Rev"
}
]
And i want this data to be convert as below format. basically the column values to be turned to the property name.
{
"parentItem": "WBP258R",
"childItem": "WBP258R",
"Color": "Rainbow",
"Color_newValue": "Rainbow1",
"Pg #": "4",
"Pg #"_newValue": "44",
"Status":"New",
"Status_newValue": "Rev",
}
looking for help
Thanks in advance
2
Answers
You could use
Array.reduce()
for this purpose.