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

268
Visualizações
Accessing a boolean property of an object in javascript always returns false?

I'm losing my mind. I have an array of objects called allAvailabilities

console.log(allAvailabilities[0]);

results in a object with various properties, one of which is:

...
isTrainee: true
...

but

console.log(allAvailabilities[0]['isTrainee']);
console.log(allAvailabilities[0].isTrainee);

results in

false
false

I'm not understanding what is preventing me from accessing the actual isTrainee value of the object property:

console.log(typeof(allAvailabilities[0]['isTrainee']));
console.log(typeof(allAvailabilities[0].isTrainee));
console.log(allAvailabilities[0]['isTrainee'].toString());
console.log(allAvailabilities[0].isTrainee.toString());

results in:

boolean
boolean
false
false

How is this possible? Am I overlooking a fundamental piece of Javascript syntax? Does this have to do with the Boolean class as described here: Why does !new Boolean(false) equals false in JavaScript?

enter image description here

The snippet works fine, what does this mean?

var allAvailabilities = [{_id: '605a5dd76f007e84f28e35fd', begin: '2021-04-03T18:00:00.000Z', end: '2021-04-03T20:30:00.000Z', season: 'regular', hostModel: 'users', isTrainee: true, season: "regular"}];


            console.log(allAvailabilities[0]);
            console.log(typeof(allAvailabilities[0]['isTrainee']));
            console.log(typeof(allAvailabilities[0].isTrainee));
            console.log(allAvailabilities[0]['isTrainee'].toString());
            console.log(allAvailabilities[0].isTrainee.toString());

How can this be? enter image description here

The original allAvailabilities array comes from an API, and each object in the array is modified to have the isTrainee property like so, immediately before calling the code I am having problems with:

enter image description here

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

0

I think it is because there is a promise asynchronous modification of isTrainee in the map. I think changing the map to for may solve the problem. For is a synchronous function rather than asynchronous.

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