title: I need to create a custom tree data-structure using JavaScript
body: <p>I looked up this basic format for a tree structure in javascript:</p>
  
  <pre><code>function Tree(parent, child, data) {
      this.parent = parent;
      this.children = child || [];
      this.data = data;
      this.addNode ...
      this.addChild ...
  }
  </code></pre>
  
  <p>the problem I have is making a tree that is "long" with this. The data I'm using is a list of streets on a trail that is almost one straight path, but there are a couple of small splits in the trail, the data would look something like:</p>
  
  <pre><code>A -&gt; 
  B -&gt; 
  C -&gt; 
  D -&gt; E,F   
  E -&gt; 
  G -&gt; 
  H    
  F -&gt; I  
  I -&gt; J  
  J -&gt; K,L   
  K -&gt;
  M -&gt; 
  N
  L -&gt; O
  O -&gt; P
  </code></pre>
  
  <p>I'd like to avoid code that looks like:</p>
  
  <pre><code>tree.children[0].children[0].children[0].addNode("E");
  tree.children[0].children[0].children[0].push("F");
  </code></pre>
  
  <p>so one of my questions is how to traverse the tree, simply by saying?</p>
  
  <pre><code>node = tree;
  while(node.children != null)
      node = node.children[0];
  </code></pre>
  
  <p>if you could help me out, I'd appreciate it, thanks,</p>
  
  <p>mathacka</p>