Some algorithm
by ShaCP
JavaScript
const nodes = [{
index: 1,
children: [2, 3]
},
{
index: 2,
children: [4, 5]
}
]
// get index of node
let index = 1;
// log index of node
console.log(index);
// get node
let node = nodes.find(node => node.index === index);
// get children of node
let children = node?.children;
// check for children
console.log(children);
// get index of node;
index = children[0];
// log index of node
console.log(index);
// get node
node = nodes.find(node => node.index === index);
// get children of node
children = node?.children;
// check for children
console.log(children);
// get index of node;
index = children[0];
// log index of node
console.log(index);
// get node
node = nodes.find(node => node.index === index);
// get children of node
children = node?.children;
// check for children
console.log(children);