Given the nested object:
{
name: 'UK',
toggled: false,
active: false,
children: [{
name: 'Region 1',
active: false,
toggled: false,
children: [{
name: 'Heathrow T1',
toggled: false,
active: false,
children: []
},
{
name: 'HTT',
toggled: false,
active: false,
children: []
},
]
},
{
name: 'Region 2',
active: false,
toggled: false,
children: [{
name: Gatwick North,
active: false,
toggled: false,
children: []
}]
}
]
}
and the given path
['UK', 'Region 2', 'Gatwick North']
how can I manage to add active/toggled properties to true for the path in the nested object matching the above array.
The output should be the following:
{
name: 'UK',
toggled: true,
active: true,
children: [{
name: 'Region 1',
active: false,
toggled: false,
children: [{
name: 'Heathrow T1',
toggled: false,
active: false,
children: []
},
{
name: 'HTT',
toggled: false,
active: false,
children: []
},
]
},
{
name: 'Region 2',
active: true,
toggled: true,
children: [{
name: 'Gatwick North',
active: true,
toggled: true,
children: []
}]
}
]
}
I was trying to implement this with recursion with no success so far. I was searching through questions and none of them matched my current situation.