I have a function that iterates through an array messages
.
That looks like this:
const messages = args;
for (var i=0; i<=messages.length; i++) {
if (typeof messages[i] === "object") {
console.log('do something');
}
}
My messages
constant looks like this:
[ { response: { entities: [], intents: [Array] } },
{ response: { entities: [], intents: [Array] } },
resumed: 0,
childId: '*:getLuisModel' ]
For some reason my application skips right over the conditional and doesn't execute anything inside the codeblock for all indices of my array.
When going into debug it with pry, I am able to run typeof messages[i]
and get an object
returned
I managed to get past the conditional by using if (typeof messages[i] !== undefined) {
But now when I have it log messages[i].response
it says it is undefined. In my debugger when I access that variable it responds with objects
Aucun commentaire:
Enregistrer un commentaire