How to tile the data of bifurcation tree structure

title

var tree = [
      {
        name:"a",
        children:[
            {
                name:"aa",
                children:[
                    {
                        name:"aaa"
                    },
                    {
                        name:"aaa1"
                    },
                    {
                        name:"aaa2"
                    },
                    {
                        name:"aaa3"
                    }
                ]
            },
            {
                name:"aa1",
                children:[
                    {
                        name:"aaaa1"
                    },
                    {
                        name:"aaaa2"
                    }
                ]
            }
        ]
    },
    {
        name:"b",
        children:[
            {
                name:"bb",
                children:[
                    {
                        name:"bbb",
                        children:[
                            {
                                name:"bbbb1"
                            }
                        ]
                    },
                    {
                        name:"bbb1"
                    },
                    {
                        name:"bbb2"
                    },
                    {
                        name:"bbb3"
                    }
                ]
            }
        ]
    }
]

requirements
returns an array of each level

[
    ["a"],
    ["b"],
    ["a","aa"],
    ["a","aa1"],
    ["a","aa","aaa"],
    ["a","aa","aaa1"],
    ["a","aa","aaa2"],
    ["a","aa","aaa3"],
    ["a","aa1","aaaa1"],
    ["a","aa1","aaaa2"],
    ["b","bb"],
    ["b","bb","bbb"],
    ["b","bb","bbb1"],
    ["b","bb","bbb2"],
    ["b","bb","bbb3"],
    ["b","bb","bbb","bbbb1"]
]
May.22,2021

The

code comes step by step, of course, traversing the print, and then the output meets the standard. In the end, the order is the same.

var log = (_tree,_parent = []) => {
    _tree.forEach((item)=>{
        console.log(_parent.concat(item.name));
    });
    _tree.forEach((item)=>{
        item.children && log(item.children, _parent.concat(item.name))
    })
}
log(tree)

clipboard.png

clipboard.png

clipboard.png

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e48c9d-44ce5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e48c9d-44ce5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?