title: Filtering an array of objects based on their ID attribute
body: <p>Using iTunes' Search API I'm looking to grab a collection of songs from an album based on a specific criteria. I managed to get half of this done with the help of this this <a href="https://stackoverflow.com/a/17099280/3046413">solution</a>. The only problem is that there are times where an album can either be clean or explicit, which ultimately outputs duplicate songs.</p>
  
  <p>I thought that the best solution in this case would be to grab the <strong>first available</strong> (and sometimes only) collection of songs based on their <code>collectionId</code>. Unfortunately this value isn't known offhand like the ones I pass in my <code>filter()</code> function.</p>
  
  <p>How can I cleanly select just one group leveraging the code below:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function() {
    iTunesSearch("Beauty Behind the Madness", "The Weeknd");
  
    function iTunesSearch(album, artist, callback) {
      var results;
  
      $.getJSON("http://itunes.apple.com/search?term=" + album + "&amp;entity=song&amp;callback=?", function(data) {
        results = data["results"];
        console.log( filter(results, { collectionName: album, artistName: artist }) );
      });
    }
  
    function filter(arr, criteria) {
      return arr.filter(function(obj) {
        return Object.keys(criteria).every(function(c) {
          return obj[c] == criteria[c];
        });
      });
    }   
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>