title: Set variable to subset of array by condition in js
body: <p>I am relatively new to JS and would like to find the best method to set one variable equal to a subset of another variable another based on a dynamic condition. </p>
  
  <p>In the example below,</p>
  
  <ul>
  <li><p><code>clickedCode</code> is a string that changes after each click event (all of the code below is within a click.event function).  </p></li>
  <li><p><code>features</code> is an array of features with 400 elements, each containing a <code>properties</code> object which in turn contains elements such as latitude, longitude, etc.</p></li>
  <li><p><code>cities</code> is an empty array </p>
  
  <pre><code>      var clickedCode // dynamically changing string
        var cities = [];
        var features = map.queryRenderedFeatures({layers:['uni']});
  </code></pre></li>
  </ul>
  
  <p>for example, if I log some properties of the first <code>feature</code>, I will see:</p>
  
  <pre><code>var lon = features[0].properties.lon
  var lat = features[0].properties.lat
  var code = features[0].properties.code
  
  console.log("" + lon + " " + lat + " " + code);
  </code></pre>
  
  <p><code>4.7005 50.8798 EMPHID</code></p>
  
  <p>My objective is to subset <code>features</code> where <code>features[i].properties.code</code> is equal to <code>clickedCode</code> and then set <code>cities</code> equal to the resulting array so that roughly : </p>
  
  <p><code>cities = features where features[i].properties.code === clickedCode</code></p>
  
  <p>Any advice and explanation of structuring this in javascript would be helpful </p>