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?
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());
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: