I'm attempting to dynamically filter an array based on user choices from multiple drop down menus. I want the filtering process to only consider the selected values from the drop downs and ignore any dropdown where a selection was not made. Is there a more efficient way to achieve this without resorting to a series of if/else
statements?
This is my current approach, but I'm exploring possibilities for streamlining the process:
filterOptions() {
if (this.name != undefined && this.age != undefined) {
this.filteredOptions = this.Options
.filter(x => x.name == this.name)
.filter(x => x.age == this.age);
} else if (this.name == undefined && this.age != undefined) {
this.filteredOptions = this.Options
.filter(x => x.age == this.age);
} else if (this.name != undefined && this.age == undefined) {
this.filteredOptions = this.Options
.filter(x => x.flcaLoan == this.name);
} else {
this.filteredOptions = this.Options;
}
}