const res = [ { name:'a', children:[ { name:'b', children:[] } ] }, { name:'c', children:[ { name:'d', children:[ { name:'e', children:[] } ] } ] }, ] let arr = [] function loop(children){ if(children.length){ children.forEach(d=>{ arr.push(d.name); loop(d.children) }) } } loop(res); console.log(arr);