title: How to filter array within array of objects in javascript?
body: <p>I have an array of objects containing information about movies. Every object has a value for genre. That value can be either a string or an array. </p>
  
  <p>I am fetching a genre from the query string and saving it to a variable called genre. Now I want to sort out only the movies in that genre.</p>
  
  <p>My array of objects look like this:</p>
  
  <pre><code>movies = [
              {
                 title:"Apocalypse Now",
                 year: "1979",
                 genre: [
                    "drama",
                    "war"
                 ]
              },
              {
                 title:"Unforgiven",
                 year: "1992",
                 genre: [
                    "western",
                    "drama"
                 ]
              },
              {
                 title: "The big Lebowski",
                 year: "1998",
                 genre: "comedy"
              }
  ];
  </code></pre>
  
  <p>Now I have found a solution that works. But I am not happy with it because:</p>
  
  <ol>
  <li><p>It doesn't allow for more than 3 genres for every movie.</p></li>
  <li><p>It doesn't look pretty and doesn't compose well with other code. And I'm thinking there has got to be a better way but I can't find it.</p></li>
  </ol>
  
  <p>Here is what I have now:</p>
  
  <pre><code>var genre = req.query.genre;
  var movies = data.movies;
  var filtered = movies.filter(function(x){
       return x.genre == genre || x.genre[0] == genre || x.genre[1] == genre || x.genre[2] == genre;
        });
  </code></pre>