title: Javascript array variable empty on second use
body: <p>I am new to javascript from C# and have a feeling that I am not quite understanding some of the fundamentals of how variable assignment and manipulation works.
  I have a function that runs to filter some results based on year and class group.
  This works as intended the first time the function is run.   </p>
  
  <p>thisSchoolArray is populated externally and retains it's values constantly. It is filteredArray that does not update as intended. I would imagine that each time the function runs, it puts all the results of the filter into filteredArray. Below is the code:  </p>
  
  <pre class="lang-js prettyprint-override"><code>function UpdateResults() {
    var filteredArray = thisSchoolArray.filter(function (item) {
      return item.TestResults.some(e =&gt; e.TestYear === yearToDisplay);
    });
    console.log(filteredArray); //Works first time, empty next time the function runs
    var filteredClass = filteredArray.filter(x =&gt; x.ClassGroup === classToDisplay);
    filteredResults = filteredClass;
    console.log(filteredResults); //Works first time, empty next time the function runs
    table.setData(filteredResults);
    UpdateRoundScores();
  }
  </code></pre>
  
  <p>Here is whats logged to the console:
  <a href="https://i.stack.imgur.com/oX5P2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oX5P2.png" alt="enter image description here"></a></p>