title: How do I slice an array from an array of object literals?
body: <p>I have this array, in which each index contains an object literal. All of the object literals have the same properties. Some of the object literals have the same value for a given property, and I want to create a new array containing <strong>only</strong> those object literals.
  <br /><br />
  My idea is to sort the array, and slice it into a new array...
  <br /><br />
  Here is the array:<br /></p>
  
  <pre><code>var arr = [];
  
  arr[0] =
  {
      country: "United States",
      num: 27
  };
  
  arr[1] =
  {
      country: "Australia",
      num: 5
  };
  
  arr[2] =
  {
      country: "United States",
      num: 7
  };
  </code></pre>
  
  <p><br />
  So, I want to create a new array containing only those objects where the property <code>country</code> is "United States". This is my crazy idea so far, which doesn't work:<br /><br /></p>
  
  <pre><code>function getNewArray(arr)
  {
      var arr2 = [];
  
      for(var key in arr)
      {
          for(var i = 0; i &lt; arr.length - 1; i++)
          {
              if(arr.hasOwnProperty(key) &amp;&amp; arr[i].name == arr[i + 1].name)
              {
                      arr2[i] = arr.slice(key);
              }
          }
      }
  
      return arr2;
  }
  
  var arr3 = getNewArray(arr).sort();
  </code></pre>