function findPathById(id, Tree) { let res = [] function get(tree, arr = []) { Array.isArray(tree) && tree.forEach(val => { let arrX = JSON.parse(JSON.stringify(arr)) //拷贝一下数组 arrX.push(val.name) val.id === id ? (res = arrX) : val.children && get(val.children, arrX) }) } get([Tree]) return res.join(",") } const str = findPathById(4, Tree)


