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

89
Visualizações
How to fiter array with an array

I have a list of objects like this.

results = [
   { id: 1, 
     status : "Active"
     // Some other fields
     tags : [{val: 'IGM', color: 'light-success' },
             {val: 'Gated Out', color: 'light-primary' },
            ]   
   },
   // ...
]

now I want to filter objects in relation to tags, the input to filter the list is also in the form of an array using multi-select input.

like

[{value: 'Gated Out', label: 'GATED OUT'},  .. ]

I'm able to filter data of other fields but not the tags because other fields are in strings and tags are an Array.

But now How can I modify this to work with the array as well.

I'm using that approach;

  const handleTagsFilter = (value) => {
    let updatedData = []

    const dataToFilter = () => {
      if (
        status.length ||
        custom_tags.length
      ) {
        return filteredData
      } else {
        return results
      }
    }

    setCustomTags(value)
    if (value.length) {
      updatedData = dataToFilter().filter((item) => {
        const startsWith = item.status.toLowerCase().startsWith(value.toLowerCase())

        const includes = item.status.toLowerCase().includes(value.toLowerCase())

        if (startsWith) {
          return startsWith
        } else if (!startsWith && includes) {
          return includes
        } else return null
      })
      setFilteredData([...updatedData])
      setCustomTags(value)
    }
  }

That function works with filtering strings like we have the status field to Active than this work, But I'm not sure how I can modify it to work with the array as well.

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

0

Maybe something like:

let search_str = 'abc'.toLowerCase();
let filtered_results = results
  .map(v => v.tags.filter(_v => _v.val.toLowerCase().includes(search_str)))
  .filter(v => v.length)
  .reduce((a, b) => a.concat(...b), [])
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