I am having a weird issue where if I hardcode a variable, my code works. When the code sets the variable I get weird results. However using console log I can see that the variable IS the correct value. I can literally copy the console value and paste it in place of the variable, and it will work.
function CheckInboxes (boxes, count=0) {
console.log('-----------------------------------------')
console.log('checking: ' + boxes[count] + ' | ' + count)
console.log('-----------------------------------------')
OpenInbox(boxes[count]).then(box => { //If I set this to 0 or any other value count would be, it works.
console.log('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^')
console.dir(box)
console.log('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^')
if(count < boxes.length -1) {
var test = count + 1
CheckInboxes(boxes, test) }
else
console.log('FINISHED<<<<<<<<<<<<<<<<<<<<<<<<<<')
})
}
boxes is an array of mailbox names ie "inbox", "draft", "etc"
The OpenInbox function returns an object defining that inbox (folder). This includes the name. The name should match the first parameter. So OpenInbox('inbox') returns an object with a name property of "inbox" because the library searches for a folder with that name and returns the object associated with it.
The problem is, this is not what happens if its not hardcoded. Its completely random. The returned object could be draft or any other folder. Sometimes it happens to be the right folder.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> ----------------------------------------- checking: Inbox | 0
> ----------------------------------------- opening...Inbox
This clearly shows its 0 and its passing "Inbox". The result will be random though. HOWEVER, if I replace
OpenInbox(boxes[count])
with
OpenInbox(boxes[0]) //or just 'inbox'
It works. Of course this isn't practical...
So I am very confused. Console clearly shows whats being passed, yet it doesn't work unless I hardcode the value outputted in console. This shouldn't be possible. Am I missing something?
UPDATE:
So by accident I add this code:
console.dir(box)
console.log(box.name)
console.log(JSON.stringify(box))
The result is...
Notice the underlined parts are completely different.
This leads me to think its a bug in chrome console.log or something because stringify shows the data I'm expecting.

OpenInboxreturns a promise - that suggests it's doing something asynchronous, and you're probably seeing the result you do because you're not handling the callback or promise correctly. Post yourOpenInboxcode & we can see for sure.