Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Cannot figure out multiple filters combined with search

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.

  1. Build out the search params and store them into an object (ie {firstname: name, gender: gender}) and then this way I can just leave blank if empty. I don't know how to actually return that, however. I tried a few different ways and I'm not even sure if that is possible.
  2. Figure out a default value for each which likely works well with the dropdowns (gender) as I can do if (both) then male || female type of line but the search part will have an issue if blank.

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!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!