chrome devtools inconsistency array length

最后都变了- 提交于 2019-11-28 09:23:44

问题


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 becomes 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 seperate variable? I would have expected Head: [Array[2]] in that case.

I am using console.log to output the listed screenshot in Chrome Dev tools on an ubuntu virtualbox.


回答1:


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.



来源:https://stackoverflow.com/questions/21281186/chrome-devtools-inconsistency-array-length

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!