javascript 如何在 Chrome 控制台中查看扩展对象/数组?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10689475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 10:42:15  来源:igfitidea点击:

How to view extended objects/arrays in Chrome console?

javascriptgoogle-chromegoogle-chrome-devtools

提问by lukas.pukenis

When I have array of objects, when I type the name of variable in Chrome console, I get this: enter image description here

当我有对象数组时,当我在 Chrome 控制台中键入变量的名称时,我得到以下信息: 在此处输入图片说明

QUESTION:Is there some option or a flag which when turned on would display the objects and arrays extended when queried in Chrome console ?

问题:是否有一些选项或标志在打开时会显示在 Chrome 控制台中查询时扩展的对象和数组?

I use the console a lot and do inline operations within the console and each time when I modify an array I have to click on all entries to see the values.

我经常使用控制台并在控制台内执行内联操作,每次修改数组时,我都必须单击所有条目才能查看值。

I do not wantto write a loop which would console.dirout all the arrays.

我不想写一个循环来console.dir输出所有数组。

回答by abettermap

console.table()does a great job of displaying arrays neatlyin a table format.

console.table()在以表格格式整齐地显示数组方面做得很好。

回答by andypaxo

To see the entire contents of an array (or any other object, for that matter) without writing a loop, you can use JSON.stringify. This will output the whole object in JSON format, optionally indenting it.

要在不编写循环的情况下查看数组(或任何其他对象,就此而言)的全部内容,您可以使用JSON.stringify. 这将以 JSON 格式输出整个对象,可选择缩进它。

For example:

例如:

console.info(JSON.stringify([{a:1,b:2}, {c:3,d:4}], null, '  '))

will output:

将输出:

[
  {
    "a": 1,
    "b": 2
  },
  {
    "c": 3,
    "d": 4
  }
]

回答by Miguel Sanchez Gonzalez

I don't know if you know this yet but... Click in the triangles and you can see the complete object I think this is very practical.

我不知道您是否知道这一点,但是...单击三角形,您可以看到完整的对象我认为这非常实用。



edit

编辑

Ok sorry I dont read this part '=.= but you can check the console APIof firebug the chrome console supports Chrome Dev Tools: Console

好的抱歉我没有阅读这部分 '=.= 但你可以检查firebug 的控制台 APIchrome 控制台支持 Chrome 开发工具:控制台