1// 数据如下: 2const tree = [ 3 { 4 name: "数据1", 5 id: 1, 6 children: [ 7 { 8 name: "数据2", 9 id: 2, 10 children: [ 11 { 12 name: "数据3", 13 id: 3, 14 children: 15 { 16 name: "数据4", 17 id: 4, 18 children: [], 19 }, 20 ], 21 }, 22 ], 23 }, 24 ], 25 }, 26]; 27 28function findNodeById(tree, id) { 29 // .... 30} 31 32const res = findNodeById(tree, 3); 33// res 的结果为 34// { 35// name: "数据3", 36// id: 3, 37// children: [ 38// { 39// name: "数据4", 40// id: 4, 41// children: [], 42// }, 43// ], 44// }