Add index values to js and vue tree view

clipboard.png

{
        "name": "",
        index:1,
        "children":[
            {
                "name":"",
                index:2,
            },{
                "name":"",
                index:2,
                "children":[
                    {
                        "name":"",
                        index:3,
                    },{
                        "name":"",
                        index:3,
                    },
                ]
            }
        ]
    }
    

want to add their index, for each layer in this tree

Apr.03,2021


    function fun(arry){
        for(let i in arry){
            let menu = arry[i];
            if(!menu['num']){
                menu['num'] = 1;
            }
            if(menu['children'].length && menu['children']){
                for(let j in menu['children']){
                    menu['children'][j]['num'] = arry[i]['num'] + 1;
                    fun(menu['children'])
                }
            }
        }
    }
Menu