title: Javascript nested object deep search
body: <p>I want to create a function, which search for an existing key in a nested object, and reports the value.</p>
  
  <p>The problem is, if <code>input ='d'</code>, I get <code>undefined</code> and I expect <code>'test-d'</code>. 
  It looks like I miss a return when it's not found</p>
  
  <p>My code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var foo = {
    a: 'test-a',
    b: {
      myProp: 'test-prop',
      foo: {
        last: 'test-last'
      }
    },
    c: {
      d: 'test-d'
    }
  };
  
  
  var search = function(input, objs) {
    for (key in objs) {
      //   console.log(key+ '---'+ input);
      if (typeof objs[key] == 'object') {
        return search(input, objs[key]);
      } else {
        if (input == key) {
          return result = objs[input];
        }
      }
    }
  }
  console.log(search("d",foo))</code></pre>
  </div>
  </div>
  </p>