var arr = [ { id: 1, title: '我是1目录', children: [ { id: 11, title: '我是1-1目录', children: [ { id: 111, title: '我是1-1-1目录', children: [] } ] }, { id: 12, title: '我是1-2目录', children: [] } ] }, { id: 2, title: '我是2目录', children: [ { id: 21, title: '我是2-1目录', children: [] } ] } ]
flatten(arr) { return arr.reduce((result, item) => { return result.concat( item, Array.isArray(item.children1) ? this.flatten(item.children1) : [] ); }, []); }
标签:arr,扁平化,title,目录,children,item,数组,id From: https://www.cnblogs.com/wqddmg/p/17298794.html