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

84
Visualizações
filter and map in an object array

I can't retrieve the user by his customer number. I use the includes function in filter, but this returns the error: Cannot read properties of null (reading 'includes') . Despite everything I've seen on the forum, nothing solves my problem. I have an array of user object, so I make a map on the array and then I filter here is my code:

thank you very much for help

const ClientComponent = ()=>{
   const resultSearchClient = useSelector((state)=> state.reducerSearchCriteria)
   const datasClientService = useSelector((state)=> state.reducerClientAdmin.state)
   const newArray = datasClientService.map(val=>{ return val})
   const filterArray = newArray.filter(u => {return u.number_client.includes(resultSearchClient)})
  
   return(
     <div>
       <p>{filterArray} </p>
    </div>
 )
}

export default ClientComponent;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The error that you are receiving is thrown because number_client is null (instead of an array or string that you are expecting there). If you know that number_client is nullish, you can do:

const filterArray = newArray.filter(u => 
  return (u.number_client ?? '').includes(resultSearchClient)
})

If you expect a value everytime there, then there is a different problem with your data.

Also, what is the purpose of newArray? that map does nothing except for creating a shallow clone, right? If you neeed a shallow clone, you can just do const newArray = [...datasClientService]. But from what you sent here, newArray is not even needed. You can just create filterArray based on dataClientService since Array.filter method returns a new array.

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