const rows = [
{
"groupId": "ff686b1c-0d83-4e9e-ac0e-edd4ed7a1579",
"clientName": "Apple",
"Id": 110117,
"manageFunds": [
{
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea53",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
}
},
{
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea54",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
}
}
],
"size": 2,
"bulkUploadErrorMessage": ""
},
{
"groupId": "ff686b1c-0d83-4e9e-ac0e-edd4ed7a1589",
"clientName": "Mango",
"Id": 110118,
"manageFunds": [
{
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea55",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
}
},
{
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea56",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
}
}
],
"size": 2,
"bulkUploadErrorMessage": ""
},
{
"groupId": "ff686b1c-0d83-4e9e-ac0e-edd4ed7a1599",
"clientName": "Orange",
"Id": 110119,
"manageFunds": [
{
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea57",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
}
},
{
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea58",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
}
},
{
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea59",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
}
}
],
"size": 3,
"bulkUploadErrorMessage": ""
}
]
const mergeMF = input => {
const initObj = []
input.forEach(rootItem => {
const { Id, clientName, manageFunds } = rootItem
const groupId = rootItem.groupId
manageFunds.forEach(subItem => {
const newSubItem = {
...subItem,
accountId: subItem.accountId,
Id: Id,
clientName: clientName,
groupId: groupId,
}
initObj.push({
checked: false,
data: newSubItem,
isCollapsed: false,
validationErrors: subItem.errorMessages
})
})
})
return initObj
}
console.log(mergeMF(rows))