Consider an array of nested objects like the following:
const data = [
{
id: 1,
children:[
{
id: 2,
children:[
{
id: 3,
children:[
{
id: 4,
children: [],
},
{
id: 5,
children: [],
}
],
},
],
},
],
},
{
id: 8,
children:[
{
id: 9,
children:[
{
id: 10,
children:[],
},
],
},
],
},
];
If you want to create a new array with id: 3 excluded, the resulting array should be like this:
const data = [
{
id: 1,
children:[
{
id: 2,
children:[],
},
],
},
{
id: 8,
children:[
{
id: 9,
children:[
{
id: 10,
children:[],
},
],
},
],
},
];
You can exclude an id from any level, and the id along with its children should be eliminated. Do you need advice on the best approach to achieve this? Feel free to share any unsuccessful attempts you have made so far.