Quick access to categorized elements in javascript array?
<p>Say I have the following javasccript</p>

<pre><code>var myobj = {
   name: "Julia",
   birthdate: "xxxx",
   movies: [{title: "movie1", rating: 5, genre: "Horror"}, {title: "movie2", rating 3, genre: "Comedy"},{title: "movie3", rating 3, genre: "Comedy"}, {title: "movie4", rating 3, genre: "Comedy"}, {title: "movie5", rating 3, genre: "Horror"}]
}
</code></pre>

<p>I am looking for the best way to retrieve all "Horror" movies (could be comedy) without having to loop through everything in an array. I know I could create a for loop to iterate through the movies array with an if condition, but that requires me to look through every single movie. If there was some way I could do:</p>

<pre><code>horrorMovies = [//array containing all horror movies without iterating through everything to iterate through all moves to look at their genre attribute]
</code></pre>

<p>Or is it some good practice to have some additional field in myobj to be some kind of lookup table:</p>

<pre><code>myobj.genreindexes = [];
</code></pre>

<p>and have that keep track of all the genres like: genreindexes['Horror'] = '//Array indexes where element is Horror'?</p>

<p>Or is there some easy way I could do: myobj.movies['-insert genrehere-'] and get the list of movies? Any advice and samples would be appreciated.</p>

<p>If there is no ideal solution, samples using any library would be okay too.</p>
