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

203
Visualizações
Why is includes in JavaScript case sensitive?

I recently stumbled upon a bug caused by .includes() method in javascript. I wanted to return the exact result in respect to case-insensitive but for some reason this does not works

["Ford", "BMW", "Fiat"].includes("bmw");
//returns false
//expected result true

I then fixed my issue with the help of .find() like below:

!!["Ford", "BMW", "Fiat"].find(el => el.toUpperCase() === "bmw".toUpperCase());
//returns true

Can someone help me understand why includes does not work in case-insensitive situations ?

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

0

Why would it work case-insensitively? Quoth the MDN:

The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate. [...] Note: Technically speaking, includes() uses the sameValueZero algorithm to determine whether the given element is found.

sameValueZero is defined to be Object.is but with +0 and -0 being equal.

That being the case, we can try that out:

> Object.is("bmw", "BMW")
false
> Object.is("bmw", "bmw")
true
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