Arjenloeb
Arjenloeb

Reputation: 104

Why does the Chrome console show the array in different ways?

I wrote a piece of code like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        var arr = [1, 45, 37, 5, 48, 15, 37, 26, 29, 2, 46, 4, 17, 50, 52];
        console.log(arr);
    </script>
</head>
<body>

</body>
</html>

Then I found a weird thing, if I open this file in the browser then F12 to call the console, the array is simplified. And if you refresh this page, the console shows the detail of this array.

enter image description here

And if I input the url with the devtool on, it also shows the detail.

Why is that?

Upvotes: 2

Views: 138

Answers (1)

Blue
Blue

Reputation: 22921

It's simply done for performance reasons. If the console is closed, there is no sense displaying the entire array out (Which would require chrome to read the array and output it).

If the chrome devtools are open, performance is no longer an issue, because you're actually looking at the console (Which 99% of users wont do).

Upvotes: 4

Related Questions