I have an array that looks something like this:
var a = [
{
value: 'Some data',
structure: 'linear',
id: 0,
children: [
{ id: 1, value: 'Some data', structure: undefined },
{ id: 2,
value: 'Some data',
structure: 'linear',
children: [
{ id: 4, value: 'Some data', structure: undefined }
]
}
]
},
{
id: 5,
structure: undefined
value: 'Some data',
},
];
I am trying to remove all the objects which value of structure is undefined. Every matching object with no children, or matches in children hierarchy, should not exist in output array. I don't know at run time how many levels of objects will have a children array
The output should look something like this:
const output = [
{
value: 'Some data',
structure: 'linear',
id: 0,
children: [
{ id: 2, value: 'Some data', structure: 'linear' }
]
}
];