javascript 如何在chrome控制台中完全打印大数组?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16151256/
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-27 03:28:11  来源:igfitidea点击:

how to print large array fully in chrome console?

javascriptgoogle-chromeconsoleformattinggoogle-chrome-devtools

提问by static

I want to print an array (uniqueNames) in the Chrome Console:

我想在 Chrome 控制台中打印一个数组 (uniqueNames):

> console.log(uniqueNames)

but the problem I come across is that after

但我遇到的问题是之后

> ["Theodor", "Albertus", /* 95 other elements */ "Andreas", "Bernd", "Roland"…] <--- dots here

screenshot

截屏

How to print the full array like the first 100 elements? I want to copy it and use in another application. Or maybe it is possible to write this array from the Chrome Console to a file (also in one line, and not as whole log)?

如何像前 100 个元素一样打印完整的数组?我想复制它并在另一个应用程序中使用。或者也许可以将此数组从 Chrome 控制台写入文件(也在一行中,而不是整个日志中)?

采纳答案by static

just join all the elements, separated in string with "," :

只需加入所有元素,用“,”分隔在字符串中:

uniqueNames.join("\",\"")

回答by fadomire

To print the full array in the console you can do : console.log(JSON.stringify(uniqueNames))

要在控制台中打印完整数组,您可以执行以下操作: console.log(JSON.stringify(uniqueNames))

回答by James Gentes

I was looking for console.table(array):

我正在寻找console.table(数组):

enter image description here

在此处输入图片说明