title: How to do equivalent of LINQ SelectMany() just in javascript
body: <p>Unfortunately, I don't have JQuery or Underscore, just pure javascript (IE9 compatible).</p>
  
  <p>I'm wanting the equivalent of SelectMany() from LINQ functionality.</p>
  
  <pre><code>// SelectMany flattens it to just a list of phone numbers.
  IEnumerable&lt;PhoneNumber&gt; phoneNumbers = people.SelectMany(p =&gt; p.PhoneNumbers);
  </code></pre>
  
  <p>Can I do it?</p>
  
  <p>EDIT:</p>
  
  <p>Thanks to answers, I got this working:</p>
  
  <pre><code>var petOwners = 
  [
      {
          Name: "Higa, Sidney", Pets: ["Scruffy", "Sam"]
      },
      {
          Name: "Ashkenazi, Ronen", Pets: ["Walker", "Sugar"]
      },
      {
          Name: "Price, Vernette", Pets: ["Scratches", "Diesel"]
      },
  ];
  
  function property(key){return function(x){return x[key];}}
  function flatten(a,b){return a.concat(b);}
  
  var allPets = petOwners.map(property("Pets")).reduce(flatten,[]);
  
  console.log(petOwners[0].Pets[0]);
  console.log(allPets.length); // 6
  
  var allPets2 = petOwners.map(function(p){ return p.Pets; }).reduce(function(a, b){ return a.concat(b); },[]); // all in one line
  
  console.log(allPets2.length); // 6
  </code></pre>