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();
}

filteredArraybecomes empty on the second call, it means thatthisSchoolArrayoryearToDisplayhas changed. It has either become an empty array itself or no longer has any elements matchingyearToDisplayconsole.log(filteredArray.slice())orconsole.log(JSON.stringify(filteredArray)), so you get a snapshot that doesn't change.yearToDisplayorclassToDisplayare changing. Can you create a minimal reproducible example that demonstrates the problem?console.logfor debugging. Use your debugger instead ~ developers.google.com/web/tools/chrome-devtools/javascript