I am currently developing an Angular application and working on a component with the following method:
createPath(node, currentPath = []){
if(node.parent !==null) {
return createPath(node.parent, [node.data.name, ...currentPath])
} else {
return [node.data.name, ...currentPath];
}
}
Within each node, I also have an id that can be accessed using node.data.id. My goal is to store this data in an array structured like this:
[{
id:1, // accessed through node.data.id
name:"myName" // accessed through node.data.name from the above method.
}
]
This code snippet demonstrates an example of how the data should be formatted dynamically to account for any number of items during runtime.
To achieve this, I need to modify the existing code and incorporate this data structure within the same method. How can I accomplish this?