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

103
Visualizações
Trouble filtering by multiple conditions from array

Filtering with multiple options in React Redux:

filterOption:

{
    option1: ['GY'],
    option2: ['Y'],
    option3: [],
    option4: ['N'],
    option5: ['A', 'W'],
}

The filter function:

body.search.listFiltered = body.search.list.filter(
    (i) =>
        filterOption["option1"].includes(i.s) &&
        filterOption["option2"].includes(i.b) &&
        filterOption["option3"].includes(i.u.p) &&
        filterOption["option4"].includes(i.f.p) &&
        filterOption["option5"].includes(i.n.p)
);

It should work even when for example option3 is empty—it could be any other option for that matter.

Each option-x works with a particular object, such as option1 with object i.s. While option2 with i.b and so forth...

Right now it's returning an empty array [].

What am I doing wrong here?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can do something like this

const filterOption = {
option1: ['GY'],
option2: [true],
option3: [],
option4: [false],
option5: ['A', 'W']
 }
 
const array = [{b:'GY'},{s:true},{p:'A'},{x:false},{e:'A'}, {b:'GY',s:true,p:'A', x:false, e:'A'  }]

 
const result = array.filter(
(i) =>
{
const filterCheck = option => item => filterOption[option].length > 0 ?   filterOption[option].includes(item) : true

return  filterCheck("option1")(i.b) &&
    
        filterCheck("option2")(i.s) &&
    
        filterCheck("option3")(i.p) &&
    
        filterCheck("option4")(i.x) &&
    
        filterCheck("option5")(i.e)}
    
)
console.log(result)

about 4 years ago · Juan Pablo Isaza Relatório
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