I have the following object:
{
id: 1,
children: [
{id: 2},
{id: 3, children: [
{id: 4 }
]}
]
}
I want to be able to remove a specific object by using the id
property (e.g. remove the object with an id of 4). I can obviously find the object by using arr.findIndex
but how do I remove it from the enclosing array? I'm struggling with finding how to get the parent array so I can remove it. Again I know how to remove from an array using splice
but the problem I'm having is how to do this programmatically so I can remove any item from anywhere in a nested structure as above.