mirror of https://github.com/fantasticit/think.git
19 lines
332 B
TypeScript
19 lines
332 B
TypeScript
|
export function flattenTree2Array(arr = []) {
|
||
|
const res = [];
|
||
|
const loopList = [...arr];
|
||
|
|
||
|
while (loopList.length) {
|
||
|
const node = loopList.pop();
|
||
|
|
||
|
res.push(node);
|
||
|
|
||
|
if (node?.children && node?.children.length) {
|
||
|
for (const sub of node.children) {
|
||
|
loopList.push(sub);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return res;
|
||
|
}
|