node.js - 如何更改 Node console.log 打印的宽度?

标签 node.js terminal

我正在将 2d 数组打印到 Node 终端窗口,但宽度导致它们跨越多行。如何更改 Node 打印区域的宽度?这不能通过更改终端窗口的列或行来解决。 /image/XCWTT.png .更新:问题是打印带有 Node 的数组。如果我打印一个字符串,它将打印出更长的宽度,那么如何更改 Node 为数组提供某种默认宽度而不管元素数量的方式?

例如:

console.log([1,2,3,4,5,6,7,8,9,10]);

将打印

[

 1, 2, 3, 4,  5,

  6, 7, 8, 9, 10

];

而不是将它们全部放在 Node 中的一行中。

最佳答案

如果您的目的是可视化二维矩阵,您可以使用 console.table,如下例所示

a = [[1, 3, 3, 4], [2, 7, 9, 12]];

控制台.表(a)

输出如下

the output is as below

关于node.js - 如何更改 Node console.log 打印的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61624102/

相关文章:

node.js - FCM iOS : Push notifications throw invalid argument

android - 无法打开本地终端

node.js - 有没有办法在 Keystone.js 中隐藏 ID 列?

node.js - 如何中止请求?

node.js - Nodejs - Expressjs - 验证 shopify webhook

perl - Perl 中的彩色终端输出

linux - Gnome-terminal - 如何自动将选择复制到剪贴板?

linux - 如何使用 linux 终端打印每行中的每个单词?

windows - Windows命令提示符中的自定义命令

node.js - 在 promise 链中调用 process.exit() 的正确位置