title: Recursive search through and object in JavaScript
body: <p>I'm trying to do a recursive search within an object and I'm trying to find <strong>all</strong> matches based on some criteria. I am using the following function:</p>
  
  <pre><code>function checkForTitleMatch(query, node) {
      var results = [];
  
      if (node.attr.title.indexOf(query) != -1) {
          results.push = node;
      }
  
      for (var i = 0; i &lt; node.children.length; i++) {
          checkForTitleMatch(query, node.children[i]);
      }            
  
      return results;
  }
  </code></pre>
  
  <p>I don't think that there's a problem in the matching and so on - I think that the problem is in the way I return the results within the recursion.</p>
  
  <p>The result in my case is always an empty array, because the first/root element will never match(in my case) and the results of the child iterations are not correctly returned, imho.</p>
  
  <p>Can someone please correct me or point out what has to be changed in order to get the correct results, please?</p>