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

355
Visualizações
Difference between in and includes in NodeJS

I was very surprised to find out that:

> 'a' in ['a', 'b']
false
> ['a','b'].includes('a')
true

What does each command perform in NodeJS?

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

0

This is not node specific but ECMA (JS) specific.

in Operator

Checks the existence of key in the collection (similar to hasOwnPropertybut also check inherited keys in prototype chain)

includes method of Array (introduced in ES6)

Checks the existence of value in the collection

about 4 years ago · Juan Pablo Isaza Relatório

0

Array.includes() checks for the existence of a certain value in an array, while the in operator checks for the existence of a key in an object (or an index in the case of arrays like you're describing).

console.log('a' in ['a', 'b']); // false, no such key
console.log(0 in ['a', 'b']); // true, 0 is a key that exists
console.log(1 in ['a', 'b']); // true, 1 is a key that exists
console.log(2 in ['a', 'b']); // false, 2 is a key that doesn't exists

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