冉冉说
最终写法。 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']) } } } }