title: Find object by property key deep Javascript
body: <p>I have the following code:</p>
  
  <p>You can go to jsbin here..
  <a href="https://jsbin.com/wupukuhita/1/edit?js,console" rel="nofollow noreferrer">https://jsbin.com/wupukuhita/1/edit?js,console</a></p>
  
  <pre><code>var foundObjects = [];
  var findObjectByLabel = function(obj, key) {
  
      var foundObject = [];    
      for(var i in obj) {
        if(typeof obj[i] === "object"){
          if(typeof obj[i][key] !== "undefined"){
              foundObjects.push(obj[i]);
          }
          findObjectByLabel(obj[i],key);
        }
      }
      return null;
  };
  </code></pre>
  
  <p>I am iterating recursively over an object to find out if a certain property exists.
  Then if it does exist, return the parent object.</p>
  
  <p>You can check the jsbin link for a full example.</p>
  
  <p>I do not like the foundObjects which is outside the function.</p>
  
  <p>How can i put it inside the function and just return from the function the  objects that contain a certain property.</p>
  
  <p><a href="https://jsbin.com/wupukuhita/1/edit?js,console" rel="nofollow noreferrer">https://jsbin.com/wupukuhita/1/edit?js,console</a></p>