Problem description:
The Replit console displays inaccurate information about the contents of an array inside console when you run code snippet in this post inside replit.
Expected behavior:
[ ]
0
(2) [“10”, “11”]
2
Actual behavior:
(2) [“10”, “11”]
0
(2) [“10”, “11”]
2
Steps to reproduce:
Run this code snipet inside html / js / css replit and check content of console:
let secondArray = [];
console.log(secondArray);
console.log(secondArray.length);
secondArray.push('10');
secondArray.push('11');
console.log(secondArray);
console.log(secondArray.length);
Bug appears at this link:
Browser/OS/Device:
I’m using windows 11 and latest version of chromium browser.
I don’t know if this is a bug or some feature how these virtual JavaScript consoles work you have to use timers or async functions to code or otherwise console renders incorrect values in console. So this is propaby some UI issue.
After conducting further research on this matter, it appears that this is a common feature among virtual JavaScript consoles. To resolve the issue, you can navigate to the console settings and disable asynchronous rendering. I don’t know if there are any side-effect for keeping asynchronous rendering off but I suspect it might lessen performance but it makes console logs give more accurate information in some cases like in this case what i posted.