最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome DevTools - inconsistent array length - Stack Overflow

programmeradmin2浏览0评论

I seem to have stumbled upon an inconsistency in Chrome DevTools.

Above is a screenshot from the DevTools. At first, I am told that the printed object contains a Body and a Head. The head should be an array of length 1. When I expand, this array suddenly bees length 2.

When expanding the array in question I get the following:

So there seems to be an empty string in the array as well. This empty string is what is causing some problems with my code which is what prompted me to investigate.

I am mostly concerned with the DevTools output though, can anybody think of a reason why DevTools would give two different lengths for the same array?

Does DevTools automatically parse the content of an array of length one to a separate variable? I would have expected Head: [Array[2]] in that case.

I am using console.log to output the listed screenshot in Chrome DevTools on an Ubuntu VirtualBox.

I seem to have stumbled upon an inconsistency in Chrome DevTools.

Above is a screenshot from the DevTools. At first, I am told that the printed object contains a Body and a Head. The head should be an array of length 1. When I expand, this array suddenly bees length 2.

When expanding the array in question I get the following:

So there seems to be an empty string in the array as well. This empty string is what is causing some problems with my code which is what prompted me to investigate.

I am mostly concerned with the DevTools output though, can anybody think of a reason why DevTools would give two different lengths for the same array?

Does DevTools automatically parse the content of an array of length one to a separate variable? I would have expected Head: [Array[2]] in that case.

I am using console.log to output the listed screenshot in Chrome DevTools on an Ubuntu VirtualBox.

Share Improve this question edited Jan 20, 2021 at 10:58 Dan Knights 8,4084 gold badges27 silver badges54 bronze badges asked Jan 22, 2014 at 11:06 cantdutchthiscantdutchthis 34.8k17 gold badges77 silver badges116 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

This is because the initial display, the one with this format:

Object {Body: Array[20], Head: Array[1]}

Is generated when the console first logs it. After expanding, it loads all of the object's properties, and if the properties have changed in between logging it and opening it, it will show different values.

You can hover over the light-blue i that shows behind the object to see what Chrome says about this itself.

发布评论

评论列表(0)

  1. 暂无评论