so I've been staring at this thread for the past few days
javascript filter array multiple conditions
And while it offers fantastic solutions if know the filter params, what happens when I don't know them both? I have no clue how to do that.
I have a very basic filter setup going...
// check for text search values to populate names
this.searchBar.addEventListener("keyup", e => {
this.searchString = e.target.value.toLowerCase();
this.new_table();
});
// check for gender options
this.genderFilter.addEventListener("change", e => {
this.genderOption = e.target.value;
this.new_table();
});
// Build out the filter
new_table() {
const searchText = this.searchString;
let combinedFilter = this.response.filter(char => {
const name = char.first_name.includes(searchText) || char.last_name.includes(searchText);
const gender = this.genderOption;
return name || char.gender == this.genderOption;
});
this.build_table(combinedFilter);
}
// build_table is my function that takes the json data and converts it into html
This works fantastic for the OR situation, but if I change the return to &&, it requires both to be filled out to show any results.
I'm pretty new with JS but I am thinking a few ways to do it and I'm probably wrong on all.
I've searched this board and the web but I apparently suck at searching because I couldn't find anyone having a combined search+dropdown filter combo. It seems one or the other but never both.
Any help you can give would be amazing thank you!