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

查看:34
本文介绍了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天全站免登陆