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

141
Visualizações
Search doesn't work when it has spaces or different type case characters

I'm working on a search that partly works but it has some bugs, the first one is that doesn't search the characters that differen in case, for example: StackOverflow is not 'Stackoverlow`, but I want to match it even if they differ in casing.

The other problem is that doesn't search the white spaces, as long as is without spaces it works but when I try to search for example: Stack Overflow, then it doesn't find the Stack Overflow even if it exits.

This search is that made to search all values inside an object. Waiting for better code, let's see!

Here is the code:

const findIn = (arr, query) => {
  return arr.filter((obj) =>
    Object.keys(obj).some((key) => {
      if (typeof obj[key] === 'string') return obj[key].includes(query);
    })
  );
};

As requested here is how the object looks: screenshot

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

0

You can solve your problem by format your string to lowercase and remove spaces and also in your obj.

  const findIn = (arr, query) => {
     let queryFormatted = (query.toLowerCase()).trim();
     return arr.filter((obj) =>
       Object.keys(obj).some((key) => {
        if (typeof obj[key] === 'string'){
          return ((obj[key].toLowerCase()).trim()).includes(queryFormatted);
          }
     })
  );
};
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