I have a tree structure containing objects:
let tree = {id: 1, children: [{id: 2, children: [{id: 3}]}]}
My goal is to save all the id
values from this tree in a text file, indenting elements with children:
1
2
3
Currently, I am using the following function to display the elements of the tree:
show(tag: XMLtag) {
console.log(tag.show());
if (tag.getChildren().length == 0) {
return;
}
tag.getChildren().forEach((c) => {
this.show(c);
});
}
When running this function, I get the following output:
1
2
3
Is there a way to export this result to a text file or display it on a webpage with proper formatting?