jQuery grep not working on object array but for loop does <p>I'm following this tutorial here: <a href="http://ddmvc4.codeplex.com/" rel="nofollow">http://ddmvc4.codeplex.com/</a> for knockout.js. This is my first go at javascript but I think I know what I'm doing so far.</p> <p>I have a simple object array like so:</p> <pre><code>var DummyCompetition = [ { "Id": 1, "Sport": 'Powerlifting', "Title": 'Íslandsmeistaramót í klassískum kraftlyftingum', "Country": 'Iceland', "DateStart": new Date(2014, 2, 8), "DateEnd": new Date(2014, 2, 8) }, { "Id": 2, "Sport": 'Powerlifting', "Title": 'Íslandsmeistaramót í kraftlyftingum', "Country": 'Iceland', "DateStart": new Date(2014, 4, 8), "DateEnd": new Date(2014, 4, 8) } ] </code></pre> <p>and I try to filter id in a function like so</p> <pre><code>var currentCompetition = $.grep(DummyCompetition, function (c) { return c.Id == id; }); currentCompetition = new Competition(currentCompetition[0]); </code></pre> <p>where id is obtained from the URL <code>var id = url.substring(url.lastIndexOf('/') + 1);</code></p> <p>If I run my page the javascript won't load but if I filter the array with a for loop everything works fine.</p> <pre><code>for (var i = 0; i &lt; DummyCompetition.length; i++) { if (DummyCompetition[i].Id == id) { var currentCompetition = new Competition(DummyCompetition[i]); break } } </code></pre> <p>What am I doing wrong?</p>