title: Recursively Search Through a Flat Array
body: <p>I have a flat, associative array that is being grepped for any elements that match a particular parentID. I then, however, need to re-run the function with the returned results to see if there are any elements with a parentID that match the previous result. Esentially, I am trying to get all children and children of those children.</p>
  
  <p>In the array below, each element has a parent ID that matches it up with it's parent. I have a function that will grep the array for any elements that contain the parent ID that I pass to it, this works fine.</p>
  
  <pre><code>  array("id" =&gt; "Test", "parent" =&gt; "#", "text" =&gt; "Title"),
    array("id" =&gt; "Test1", "parent" =&gt; "Test", "text" =&gt; "Title1"),
    array("id" =&gt; "Test2", "parent" =&gt; "Test", "text" =&gt; "Title2"),
    array("id" =&gt; "Test3", "parent" =&gt; "Test2", "text" =&gt; "Title3") ,
    array("id" =&gt; "Test4", "parent" =&gt; "Test1", "text" =&gt; "Title4") ,
    array("id" =&gt; "Test5", "parent" =&gt; "Test1", "text" =&gt; "Title5") 
  
  
  function getChildren(id){
    var children = jQuery.grep(orig, function( n, i ) {
     return ( n.parent === id );
    });
  return children;
  
  // var children = jQuery.grep(orig, function( n, i ) {
  //     return ( n.parent === id );
  //   });
  //   $.each(children,function(a,b){
  // 
  //       getChildren(children[0]['id']);
  //   });
  }
  </code></pre>
  
  <p>After the function is run for the first time, it will return a list of children that contain that parent id. I now need to push all of those children back through the loop and get their children. Ideally, once the loop is finished, I would have a single array containing all children. Currently, the first part of the function works, but the area I commented out (where I try to pass the results back through) does not. Any help is greatly appreciated.</p>