Find an Object by id via angular <p>I'm currently handing down JSON data from Rail in the DOM. It looks like this:</p> <pre><code>&gt; gon.posts [ { id: 1, name: "Post 1", related_post_ids: [3] }, { id: 2, name: "Post 2", related_post_ids: [2, 3] }, { id: 3, name: "Post 3", related_post_ids: [1, 2] } ] </code></pre> <p>How would I be able to write some AngularJS (I'm ruby) so that I could execute this pseudocode:</p> <pre><code>// Using "Post 1" and mapping to its related posts. &gt; gon.posts[0].related_posts [ { id: 3, name: "Post 3", related_post_ids: [1, 2] } ] // Then being able to do this recursively to make development with the JSON easier: &gt; gon.posts[0].related_posts[0].related_posts [ { id: 1, name: "Post 1", related_post_ids: [3] }, { id: 2, name: "Post 2", related_post_ids: [2, 3] } ] </code></pre> <p>It would also be helpful if you could show how to do this via a <code>map</code> or <code>each</code> function with AngularJS.</p> <hr> <p>A user commented that <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter" rel="nofollow"><code>Array.prototype.filter()</code></a> would be useful, but I'm not looking for a gross solution, I'm looking for the best, minimal, DRYest solution via AngularJS.</p> <hr> <p><a href="https://github.com/emberjs/data" rel="nofollow">Ember Data</a> has a <code>find()</code> method. If I was able to use Ember and load the data up, I would be able to easily search, but I would still need something like an <code>ActiveRecord::Proxy</code> object in JS to be able to handle the delegations and I'm not sure how to meta program new object types in JS.</p>