I have tree stucture like this:
[{
...,
childCode: [
...,
childCode: []
]
},
{...,
childCode:[
]
}
]
And I want to delete all child codes...
I am able to do it wit recusion:
In my my code:
removeChild(code.childCode);
return res.json({
message: "Code deleted!"
});
recusion function:
function removeChild(code) {
if (code.length == 0) {
console.log("done");
} else
{
code.forEach(function (code) {
setTimeout(function () {
code.remove();
removeChild(code.childCode);
}, 100);
});
}
}
Is this right way to do this?