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

214
Visualizações
Is indexOf() type sensitive in javascript?

I have this function that iterates each object in an array to get their id and then filtering the result using a given id:

const id = another.id; //variable used to filter through the items
const pos = this.items.map(function(e){return e.id}).indexOf(id); //filter items with another.id
this.items.splice(pos, 1) //remove item with the same id as another.id

The another.id would sometimes be a string and sometimes be a number, it would work when the type is string but pos would become -1 indicating that indexOf() didn't find a match. The e.id's are also a typeof string.

So my question would be as the title says, is indexOf() type sensitive?

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

0

Yes, it's type sensitive according to mdn:

indexOf() compares searchElement to elements of the Array using strict equality (the same method used by the === or triple-equals operator).

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