title: From an array of objects, extract value of a property as array
body: <p>I have JavaScript object array with the following structure:</p>
  
  <pre><code>objArray = [ { foo: 1, bar: 2}, { foo: 3, bar: 4}, { foo: 5, bar: 6} ];
  </code></pre>
  
  <p>I want to extract a field from each object, and get an array containing the values, for example field <code>foo</code> would give array <code>[ 1, 3, 5 ]</code>.</p>
  
  <p>I can do this with this trivial approach:</p>
  
  <pre><code>function getFields(input, field) {
      var output = [];
      for (var i=0; i &lt; input.length ; ++i)
          output.push(input[i][field]);
      return output;
  }
  
  var result = getFields(objArray, "foo"); // returns [ 1, 3, 5 ]
  </code></pre>
  
  <p>Is there a more elegant or idiomatic way to do this, so that a custom utility function would be unnecessary?</p>
  
  <hr>
  
  <p>Note about <a href="https://stackoverflow.com/questions/6857468">suggested duplicate</a>, it covers how to convert a single <em>object</em> to an array.</p>