const selectedArr = [
{
name: 'Hello1',
number: '1211211221'
},
{
name: 'Hello2',
number: '1222121'
},
{
name: 'Hello3',
number: '121212121'
},
];
const selectedAcc = {
id: '',
name: {value: 'Fixed Assets', translations: {}},
type: 'AccountGroup'
};
const data = [
{
id: '',
name: {value: 'Assets', translations: {}},
type: 'AccountGroup',
children: [
{
id: '',
name: {value: 'Fixed Assets', translations: {}},
type: 'AccountGroup',
children: []
},
{
id: '',
name: {value: 'Current Assets', translations: {}},
type: 'AccountGroup',
children: []
}
]
},
{
id: '',
name: {value: 'Equity capital and Debts', translations: {}},
type: 'AccountGroup',
children: [
{
id: '',
name: {value: 'Equity capital', translations: {}},
type: 'AccountGroup',
children: []
},
{
id: '',
name: {value: 'Untaxed reserves', translations: {}},
type: 'AccountGroup',
children: []
},
{
id: '',
name: {value: 'Allocations and provisions', translations: {}},
type: 'AccountGroup',
children: []
},
{
id: '',
name: {value: 'Non-current ilabilities', translations: {}},
type: 'AccountGroup',
children: []
},
{
id: '',
name: {value: 'Short term ilabilities', translations: {}},
type: 'AccountGroup',
children: []
}
]
}
];
const finalResult = [
{
id: '',
name: {value: 'Assets', translations: {}},
type: 'AccountGroup',
children: [
{
id: '',
name: {value: 'Fixed Assets', translations: {}},
type: 'AccountGroup',
children: [
{
id: '',
name: {value: 'Hello1', translations: {}},
number: '1211211221',
type: 'AccountGroup'
},
{
id: '',
name: {value: 'Hello2', translations: {}},
number: '1211212311221',
type: 'AccountGroup',
},
{
id: '',
name: {value: 'Hello3', translations: {}},
number: '3232323',
type: 'AccountGroup'
}
]
}
]
}
]