Js multitree traversal problem

has a node of the template
root: [{

]
Name:
children:{
    count:7
    List:{},{},{},{},{},{},{}
}

}]
where every object in List is the same as the root structure.
how to change root into the following template node:
root: [{

]
Name:
children:[{},{},{},{},{},{},{}]

}]

Sep.09,2021

to tell you the truth, I don't understand.

function(root) {
  return [{
    children: root.children.list,
    name: root[0].name
  }]
}

add a judgment, and then the first floor recursion


Recursion:

function traverseTree(list) {
    for (let node of list) {
        if (node.children) {
            if (node.children.List) {
                node.children = node.children.List
            }
            traverseTree(node.children)
        }
    }
}

traverseTree(root)

Recursion, which is generally implemented as above. You'd better understand yourself and write it down, and you'll have no problem next time.

Menu