title: Array within object returning length of 0, even though there are elements present
body: <p>I am trying to implement a Trie in Javascript, which is easy enough but I seem to have hit a road block with my object.</p>
  
  <p>The nodes are structured as follows:</p>
  
  <pre><code>var node = {
      children: []
  }
  </code></pre>
  
  <p>Children is an array of nodes that is mapped by a letter in a string. So the string "Test" would look like this:</p>
  
  <pre><code>root = {
    children: [
        't' =&gt; {
            children: [
                'e' =&gt; {
                     children: [
                         's' =&gt; {
                              children: [
                                   't' =&gt; {
                                        children: []
                                    }
                              ]
                          }
                     ]
                 }
            ]
        }
    ]
  };
  </code></pre>
  
  <p>So each children array should have a length of 1, but if do something like <code>alert(this._root.children.length);</code> I get zero. Any thoughts on why this is happening?</p>
  
  <p><strong>Here is the rest of my implementation:</strong></p>
  
  <pre><code>function Trie() {
      this._root = {
          children: []
      };
  }
  
  Trie.prototype = {
  
      //restore constructor
      constructor: Trie,
  
      add: function (str){
          var curr = this._root,
              prev,
              currchar;
          // For each character in the string
          for(var i = 0, j = str.length; i &lt; j; i++) {
              // Insert only lowercase letters for efficiency
              currchar = str.toLowerCase().charAt(i);
              prev = curr;
              curr = prev.children[currchar];
              // Traverse until we hit a non-existant node
              if(typeof(curr) == "undefined") {
                  // Make a new node
                  prev.children[currchar] = {
                      children: []
                  };
                  curr = prev.children[currchar];
              }
          }
      }
  </code></pre>