const ClientDetails = [
{
"checked": false,
"data": {
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea53",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
},
"Id": 110117,
"clientName": "Apple",
"groupId": "ff686b1c-0d83-4e9e-ac0e-edd4ed7a1579",
},
"isCollapsed": false,
"validationErrors": [
"Some data validations failed. Please correct and submit"
]
},
{
"checked": false,
"data": {
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea54",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
},
"Id": 110117,
"clientName": "Apple",
"groupId": "ff686b1c-0d83-4e9e-ac0e-edd4ed7a1579",
},
"isCollapsed": false,
"validationErrors": [
"Some data validations failed. Please correct and submit"
]
},
{
"checked": false,
"data": {
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea55",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
},
"Id": 110118,
"clientName": "Mango",
"groupId": "ff686b1c-0d83-4e9e-ac0e-edd4ed7a1589",
},
"isCollapsed": false,
"validationErrors": [
"Some data validations failed. Please correct and submit"
]
},
{
"checked": false,
"data": {
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea56",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
},
"Id": 110118,
"clientName": "Mango",
"groupId": "ff686b1c-0d83-4e9e-ac0e-edd4ed7a1589",
},
"isCollapsed": false,
"validationErrors": [
"Some data validations failed. Please correct and submit"
]
},
{
"checked": false,
"data": {
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea57",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
},
"Id": 110119,
"clientName": "Orange",
"groupId": "ff686b1c-0d83-4e9e-ac0e-edd4ed7a1599",
},
"isCollapsed": false,
"validationErrors": [
"Some data validations failed. Please correct and submit"
]
},
{
"checked": false,
"data": {
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea58",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
},
"Id": 110119,
"clientName": "Orange",
"groupId": "ff686b1c-0d83-4e9e-ac0e-edd4ed7a1599",
},
"isCollapsed": false,
"validationErrors": [
"Some data validations failed. Please correct and submit"
]
},
{
"checked": false,
"data": {
"accountId": "eb9e38a8-2e0e-46c2-b50a-fa5c7c18ea59",
"address": {
"address1": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
},
"Id": 110119,
"clientName": "Orange",
"groupId": "ff686b1c-0d83-4e9e-ac0e-edd4ed7a1599",
},
"isCollapsed": false,
"validationErrors": [
"Some data validations failed. Please correct and submit"
]
}
]
const deMergeMF = manageFunds => {
const result = [
...manageFunds
.reduce((r, { Id, clientName, groupId, ...rest }) => {
r.has(groupId) ||
r.set(groupId, {
groupId,
clientName,
Id,
manageFunds: [],
})
r.get(groupId).manageFunds.push({ ...rest })
return r
}, new Map())
.values(),
]
return result.map(alterResult => ({...alterResult, size: alterResult.manageFunds.length, bulkUploadErrorMessage: ''}))
}
console.log(deMergeMF(ClientDetails.map(item => item.data)))