I have a data object say -
const data = {
'root': [
{
id: 1,
name: 'demo',
children: [
{
id: 2,
name: 'demo2',
children: [
{
id: 3,
name: 'demo3',
children: []
},
{
id: 4,
name: 'demo4',
children: [
{
id: 5,
name: 'demo5',
children: []
}
]
}
]
}
]
}
]
}
Now my question is if I want to perform an add/edit/delete operation, for an example, I want to edit an object which has the id = 5
then I have to visit root[0].children[0].children[1].children[0]
, this route and complete the task. I think it would be expensive and the object may have more nested children
property.
So is there any other structure by which I can re-arrange my object and perform fast add/edit/delete operations?