title: Most concise way to use jQuery grep() to find match?
body: <p>I am wondering if there is a way to improve the elegance of this function:</p>
  
  <pre><code>  function findById(id) {
      var items = [
        { Id: 1, Value: 'My value 1' },
        { Id: 2, Value: 'My value 2' }
       ];
  
      var result = $.grep(items, function (obj) { return obj.Id === id; });
  
      return result.length &gt; 0 ? result[0] : null;
    }
  </code></pre>
  
  <p>In particular, I'd rather it looked something like this:</p>
  
  <pre><code>  function findById(id) {
      var items = [
        { Id: 1, Value: 'My value 1' },
        { Id: 2, Value: 'My value 2' }
       ];
  
      return $.grep(items, function (obj) { return obj.Id === id; })[0] || null;
    }
  </code></pre>
  
  <p>That is obviously a big pile of fail, but the idea is that perhaps there is a cleaner way of writing the function. Not a big deal but I thought I'd write this up in case I am missing something.</p>
  
  <p>[Edit] As pointed out, the ideal code works just fine. I had incorrectly assumed accessing the first element of an empty array would throw an error, but instead it returns undefined. Thanks all!</p>