I am working with a 1D deep nested array structure:
nestedObj: [
{ id: 1, parentId: null, taskCode: '12', taskName: 'Parent one', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []},
{ id: 2, parentId: 1, taskCode: '12100', taskName: 'Child one', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []},
{ id: 3, parentId: 2, taskCode: '12200', taskName: 'SubChild one', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []},
{ id: 4, parentId: 3, taskCode: '122001', taskName: 'Sub-dub-Child one', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []},
{ id: 5, parentId: null, taskCode: '13', taskName: 'Parent two', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []}
]
In the above data structure, the tree view with taskName displayed is as follows:
-> Parent one
-> Child one
-> SubChild one
->Sub-sub-Child one
-> Parent two
If I were to remove a node (let's say Parent one), then all its nested children (up to Sub-sub-Child one) should also be deleted. How can I achieve this using recursion?
Thank you for your help