title: How would I represent this workflow as a JavaScript data structure?
body: <p>I'm dealing with a pretty complex workflow that I want to represent as a JavaScript data structure. The flow is essentially a set of questions and answers where the answer to one question affects which question is asked next. The following is a basic example of what the flow might look like:</p>
  
  <p><img src="https://i.stack.imgur.com/Aym9t.png" alt="enter image description here"></p>
  
  <p>I'm not sure how to convert this flow into a JavaScript object that's easy to work with. I would ideally like to have a structure that's easy to loop/recurse through and that is easily modifiable, so that if someone wanted to change the flow at a later point, they could do so without having to make too many changes.</p>
  
  <p>I feel like this is some sort of weird tree structure where nodes can have more than one parent. (I'm not sure what data structures like this are called.)</p>
  
  <p>Anyway, the only idea I've had is to assign an ID to each node, and then create an array of node objects like the following:</p>
  
  <pre><code>{
    id: 5,
    parents: [2, 3],
    children: [6, 7, 8]
  }
  </code></pre>
  
  <p>However, that seems really inflexible when it comes to looping through the node objects (I could be wrong though).</p>
  
  <p>If anyone could please offer some instruction/guidance on what kind of data structure(s) I should look into and possibly how to implement them in JavaScript, I would be greatly appreciative.</p>
  
  <p>Thank you very much in advance.</p>