title: Filter an array of objects with jquery grep but the criteria is a variable
body: <p>I'm trying to filter down an array of objects.  But the property of the object to filter on is defined elsewhere as a variable and not 100% how i can construct the dot-notation syntax.</p>
  
  <p>So i have a array object like this</p>
  
  <pre><code>var listings = [
      {"id" : "1", "name":"a name", "surname" : "a surname"},
      {"id" : "2", "name":"b name", "surname" : "b surname"},
      {"id" : "3", "name":"c name", "surname" : "c surname"}
  ]
  </code></pre>
  
  <p>I have a variable the specifies what property of the object to filter on. This variable isn't always set to name. In the example above it could be on id,name or surname.</p>
  
  <pre><code>var filter = 'id'
  </code></pre>
  
  <p>A var for the filter val to look for</p>
  
  <pre><code>var filterVal = '2'
  </code></pre>
  
  <p>Then i have this grep call.</p>
  
  <pre><code>listings = $.grep(listings, function (obj, index) {
  return  obj.id === filterVal;
  });
  </code></pre>
  
  <p>But instead of having obj.id hard coded I want something like:</p>
  
  <pre><code>obj."value of filter variable" === filterVal
  </code></pre>
  
  <p>Thanks in advance</p>
  
  <p>Ben</p>