JSFiddle - React, Tailwind, and code Playground
HTML
Post:<br/>
<div id="post"/>
JavaScript
function removeByeChildren(parent) {
// recurse through array and toggle/hide any Match Byes
if(!parent.children)
return;
var i = 0;
while(i < parent.children.length) {
var data = parent.children[i].data;
if (typeof data != "undefined" && data.bye == "byeM") {
// remove child - could save it in _children if you wanted
var child = parent.children.splice(i,1);
// length of child list reduced, i points to the next child
}
else {
// not a bye - recurse
removeByeChildren(parent.children[i]);
// all the child's bye's are removed so go to the next child
i++;
}
}
}
var root =
{ children: [
{children: [{children: [{},{}], data: {bye:'byeM'}},{children: [{},{}]}]},
{children: [{children: [{},{}]},{children: [{},{}]}]}
]};
console.log('Pre',JSON.stringify(root));
removeByeChildren(root);
console.log('Post',JSON.stringify(root));
$('#post').html(JSON.stringify(root));