JavaScript Array Console.log Reporting Issue inside Replit

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.

1 Like

It produce expected output correctly if coded like this:

let secondArray = [];

console.log(secondArray);
console.log(secondArray.length);

setTimeout(function() {
  secondArray.push('10');
  secondArray.push('11');
  console.log(secondArray);
  console.log(secondArray.length);
}, 100);

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.

Can you please format your code by triple backticks?

1 Like

This is maybe an Eruda bug (I think replit uses eruda still), maybe make an issue on Issues · liriliri/eruda · GitHub just in case.

Hello @HexScript! Please edit your post’s code to be formatted like this:

```
Your code here
```

So that it is easier for staff and members of the community to help you with your issue!

Also see this guide on how to share your code:

PS: if you cannot edit your post, please read around a little to increase your trust level and let you access editing your posts.

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. :thinking: :smirk:

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.