6

解决 Node.js 中通过 console.log 打印数组时长度的限制

 2 years ago
source link: https://wayou.github.io/2021/08/20/%E8%A7%A3%E5%86%B3_Node_js_%E4%B8%AD%E9%80%9A%E8%BF%87_console_log_%E6%89%93%E5%8D%B0%E6%95%B0%E7%BB%84%E6%97%B6%E9%95%BF%E5%BA%A6%E7%9A%84%E9%99%90%E5%88%B6/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

解决 Node.js 中通过 console.log 打印数组时长度的限制

2021 8 月 20 日

解决 Node.js 中通过 console.log 打印数组时长度的限制

Node.js 中通过 console.log 打印组数到命令时,会有数量限制,超出部分会隐藏而展示成如下形式:

[ 'item',
  'item',
  'item',
  <...cut...>
  'item',
  'item',
  'item',
  ... 400 more items ]

解决办法还蛮多的,参考这个 StackOverflow 上的回答,这里给出最便捷的:

const util = require('util')
console.log(util.inspect(array, { maxArrayLength: null }))

我为什么会发现这么个问题呢,因为老早之前写了个 Webpack 插件打印些调试信息,有人提 issues 报了这个问题。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK