I have an array of objects which I filter with two different arrays. The array is a list of study classes that I want to filter by grade and subject.
I came up with this code:
this.schoolActivity.filter(x => {
return (
this.activeSubjects.includes(x.subject.toLowerCase()) &&
this.activeGrades.includes(x.grade)
);
});
which works fine but the issue here is that if there are no active subjects (subject to filter by) or the same for a grade, then nothing returns. Any idea how can I improve this filter by adding logic to the only filter by subject/grade if active ones exist?
x.subjectis blank, orthis.activeSubjectsis empty?