Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

javascript - Chrome DevTools - inconsistent array length

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

Screenshot

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:

Screenshot

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...