javascript Uint8Array access doesn't return expected result (compared with expanding out the contents of the array in chrome console) -


when console.log uint8array chrome dev console, can expand out contents , view elements. when console.log access array, array[512], don't see saw when expanded out.

example taken directly source code:

console.log(this.memory);      // logs [0, 0, 0, ......] console.log(this.memory[512]); // logs 0 

when expand out array first log, can see index 512 has value 34, not 0.

here screenshot console:

enter image description here

right below that, number 0 logged when logged this.memory[512]. tried running through array for-loop make double sure. logged out 0's! don't know else try.

update: more weirdness. attached array window play around in console:

window.memory = this.memory // in chrome, lets see happens window.memory[512]; -> 34 

here jsfiddle pretty code. strangeness happening around lines 113-116. work in progress chip8 emulator: https://jsfiddle.net/ybd6ntks/2/

update 2: if run window.memory[512]; source code, 0. if run window.memory[512]; within chrome console, 34.

it turned out async issue. fixed waiting until knew sure array had been updated before moving on program. set flag on last byte, , checked if set or not. if not, settimeout , tried again.