The backend is sending an object that contains an array of objects, which in turn contain more arrays of objects, creating a tree structure.
I need a way to navigate between these objects by following the array and then back again. What would be the most efficient approach to achieve this in TypeScript?
I attempted using forEach, but encountered difficulties navigating back. Nested for loops are not viable either due to varying levels of arrays present. I thought about using an iterator, but my knowledge of Angular/TypeScript is limited.
Below is a snippet of the data. It represents a questionnaire where each question needs to be displayed individually.
"questionId": 1,
"parent": null,
"description": "Question 1?",
"children":
[
{
"questionId": 2,
"parent": 1,
"description": "Question 2?",
"children":
[
{
"questionId": 4,
"parent": 2,
"description": "Question 4?",
"children": []
}
]
},
{
"questionId": 3,
"parent": 1,
"description": "Question 3?",
"children": []
}
]
Apologies if my explanation is unclear or incomplete. This platform is new to me.