Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda