how to tile a tree-structured array into a normal array?
related codes
cost treeNode = [{
parentId: 0,
title: "1",
id:1,
children: [{
parentId: 1,
title: "1-1",
id:22,
},{
parentId: 1,
title: "1-2",
id:33,
}],
},{
parentId: 0,
title: "2",
id:2,
children: [{
parentId: 2,
title: "2-1",
id:44,
},{
parentId: 1,
title: "2-2",
id:55,
}],
}];
becomes this structure
const arr = [{
id:1,
parentId:0,
title: "1"
},{
id:22,
parentId:1,
title: "1-1"
},{
id:33,
parentId:1,
title: "1-2"
}{
id:2,
parentId:0,
title: "2"
},{
id:44,
parentId:1,
title: "2-1"
},{
id:55,
parentId:2,
title: "2-2"
}];