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.
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:
function UpdateResults() {
var filteredArray = thisSchoolArray.filter(function (item) {
return item.TestResults.some(e => e.TestYear === yearToDisplay);
});
console.log(filteredArray); //Works first time, empty next time the function runs
var filteredClass = filteredArray.filter(x => x.ClassGroup === classToDisplay);
filteredResults = filteredClass;
console.log(filteredResults); //Works first time, empty next time the function runs
table.setData(filteredResults);
UpdateRoundScores();
}