title: filter array of objects javascript
body: <p>I have this array of objects:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var vigilantes = [
      {
          "fullName": "Tony Stark",
          "classRoom": "XI",
          "city": "NYC",
          "job": "Engineer",
          "studies": "MIT",
          "markAV": 10,
      },
      {
          "fullName": "Hulk Green",
          "classRoom": "IV",
          "city": "Beijing",
          "job": "Physicist",
          "studies": "Harvard",
          "markAV": 9,
      },
      {
          "fullName": "Thor Norse",
          "classRoom": "XX",
          "city": "Oslo",
          "job": "God",
          "studies": "U of Norway",
          "markAV": 8.5,
      },
      {
          "fullName": "Bruce Wayne",
          "classRoom": "XIX",
          "city": "Gotham",
          "job": "Richamn",
          "studies": "U of Gotham",
          "markAV": 8,
      },
      {
          "fullName": "Peter Parker",
          "classRoom": "XI",
          "city": "NYC",
          "job": "Photographer",
          "studies": "Syracuse U",
          "markAV": 7.5,
      }
  ]</code></pre>
  </div>
  </div>
  </p>
  
  <p>And I would like to filter it by city, BUT I need to create a new array with the objects which share the same city. In this example the desired result would be an array of two objects because they share NYC as a city:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var vigilantes = [
      {
          "fullName": "Tony Stark",
          "classRoom": "XI",
          "city": "NYC",
          "job": "Engineer",
          "studies": "MIT",
          "markAV": 10,
      },    
      {
          "fullName": "Peter Parker",
          "classRoom": "XI",
          "city": "NYC",
          "job": "Photographer",
          "studies": "Syracuse U",
          "markAV": 7.5,
      }
  ]</code></pre>
  </div>
  </div>
  </p>
  
  <p>I know I could filter by city like this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var nyc = "NYC"
  var oslo = "Oslo"
  var gotham = "Gotham"
  var beijing = "Beijing"
  
  var res = vigilantes.filter(function (vigilante) {
    return beijing.indexOf(vigilante.city) &gt;= 0; 
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>But I'm looking for something easier!</p>
  
  <p>Thank you very much for your help, as you can see I'm kind of new in programming!</p>