js递归问题

请问如下需求如何实现:

const data = {
    id: '1',
    children: [{
            id: '11',
            children: [{
                    id: '111'
                },
                {
                    id: '112',
                    children: []
                }
            ]
        },
        {
            id: '12',
            children: [{
                id: '121',
                children: [{
                    id: '1211',
                    children: []
                }]
            }]
        }
    ]
}

getPath(data, '112') //  ==>  ['1','11','112']

getPath(data, '1211') //  ==>  ['1','12','121','1211']


手掌心
浏览 445回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript