title: Pluck specific javascript value from an object based on an array of indexes
body: <p>Given a nested object like this:</p>
  
  <pre><code>var cars = {
      "bentley": {
          "suppliers": [
              {
              "location": "England",
              "name": "Sheffield Mines"}
          ]
          // ...
      }
  };
  </code></pre>
  
  <p>and an array like this <code>["bentley", "suppliers", "0", "name"]</code>, is there an existing function that will pluck the deepest element, i.e. <code>pluck_innards(cars, ['bentley', "suppliers", "0", "name"])</code> and that returns "Sheffield Mines".</p>
  
  <p>In other words, is there a function (which I will name <code>deep_pluck</code>) where </p>
  
  <pre><code>deep_pluck(cars, ['bentley', 'suppliers', '0', 'name']) 
           === cars['bentley']['suppliers']['0']['name']
  </code></pre>
  
  <p>It seems to me that this is simple, yet common enough, to have probably been done in one of the Javascript utility libraries such as <a href="http://jquery.com/">jQuery</a> or <a href="http://lodash.com/">lo-dash</a>/underscore - but I have not seen it.</p>
  
  <p>My thought is something trivial, along the lines of:</p>
  
  <pre><code>function deep_pluck(array, identities) {
      var this_id = identities.shift();
      if (identities.length &gt; 0) {
          return deep_pluck(array[this_id], identities);
      }
      return array[this_id];
  }
  </code></pre>
  
  <p>Which I have posted <a href="http://jsfiddle.net/bmh_ca/VF2ja/">on jsFiddle</a>.</p>
  
  <p>It would be helpful of course if the function were smart enough to identify when numerical indexes in arrays are needed. I am not sure offhand what other caveats may be a concern.</p>
  
  <p>This is all a fairly long question for something I imagine has already been cleverly solved, but I thought to post this as I would interested in seeing what solutions are out there.</p>