util.inspect.defaultOptions
defaultOptions
值允许自定义 util.inspect
使用的默认选项。这对于像 console.log
或 util.format
这样隐式调用 util.inspect
的函数很有用。它应设置为包含一个或多个有效 util.inspect()
选项的对象。也支持直接设置选项属性。
¥The defaultOptions
value allows customization of the default options used by
util.inspect
. This is useful for functions like console.log
or
util.format
which implicitly call into util.inspect
. It shall be set to an
object containing one or more valid util.inspect()
options. Setting
option properties directly is also supported.
import { inspect } from 'node:util';
const arr = Array(156).fill(0);
console.log(arr); // Logs the truncated array
inspect.defaultOptions.maxArrayLength = null;
console.log(arr); // logs the full array
const { inspect } = require('node:util');
const arr = Array(156).fill(0);
console.log(arr); // Logs the truncated array
inspect.defaultOptions.maxArrayLength = null;
console.log(arr); // logs the full array