Chrome DevTools-数组长度不一致 [英] Chrome DevTools - inconsistent array length

查看:57
本文介绍了Chrome DevTools-数组长度不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎偶然发现了Chrome DevTools中的不一致之处.

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

上图是DevTools的屏幕截图.首先,我被告知打印的对象包含一个 Body 和一个 Head .头应该是长度为 1 的数组.当我扩展时,该数组突然变为长度 2 .

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.

尽管我最关心的是DevTools的输出,但是有人能想到为什么DevTools会为同一数组给出两个不同的长度吗?

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?

DevTools是否自动将长度为1的数组的内容解析为单独的变量?在这种情况下,我本应期望 Head:[Array [2]] .

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.

我正在使用 console.log 在Ubuntu VirtualBox上的Chrome DevTools中输出列出的屏幕截图.

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

推荐答案

这是因为初始显示的格式如下:

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.

您可以将鼠标悬停在显示在对象后面的浅蓝色 i 上方,以查看Chrome浏览器对此内容的看法.

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

这篇关于Chrome DevTools-数组长度不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆