I am dealing with a rather complex workflow that I want to represent as a JavaScript data structure. A flow is essentially a set of questions and answers in which the answer to one question affects the question that is asked next. The following is a basic example of how a stream might look:

I'm not sure how to convert this stream to a JavaScript object that is easy to work with. Ideally, I would like to have a structure that can be easily rewritten and rewritten, and this is easily modified, so if someone wants to change the stream at a later point, they can do it without making too many changes.
It seems to me that this is some kind of strange tree structure, where nodes can have more than one parent. (I'm not sure what data structures like this are being called.)
In any case, the only idea I got is to assign an identifier for each node and then create an array of node objects, as shown below:
{ id: 5, parents: [2, 3], children: [6, 7, 8] }
However, this seems really inflexible when it comes to looping through node objects (I could be wrong, though).
If anyone can offer some instructions / recommendations about which data structure I should study, and possibly how to implement them in JavaScript, I would be very grateful.
Thank you in advance.
javascript data-structures recursion nodes
HartleySan
source share