我想更改换行符之前显示数组的字符数或元素数的设置。 由于某种原因,在 6 个元素之后会发生这种情况:
console.log([1, 2, 3, 4, 5])
console.log([1, 2, 3, 4, 5, 6, 7])
这将产生以下输出:
[ 1, 2, 3, 4, 5 ]
[
1, 2, 3, 4,
5, 6, 7
]
但是,我更喜欢以下输出:
[ 1, 2, 3, 4, 5 ]
[ 1, 2, 3, 4, 5, 6, 7 ]
有谁知道如何更改这些设置? 当我尝试用谷歌搜索时,有各种关于代码内换行和一般日志记录的建议,但我找不到任何有此问题的人。
希望这是一个简单的事情。 提前致谢。 兄弟,直到
使用
util.inspect
。
breakLength: 60
,似乎知道如何自动换行二维数组。maxArrayLength: Infinity
)import util from 'util';
// const arr = Array.from({ length: 20 }, (_, i) => Math.floor(Math.random() * 100));
// const arr = [59, 2, 71, 94, 43, 15, 83, 85, 41, 52, 89, 67, 62, 49, 15, 1, 26, 71, 94, 60];
const arr = [
[59, 2, 71, 94, 43, 15, 83, 85, 41, 52, 89, 67, 62, 49, 15, 1, 26, 71, 94, 60],
[37, 42, 68, 78, 52, 95, 66, 61, 22, 38, 54, 73, 70, 14, 46, 57, 83, 87, 86, 35],
];
console.log(arr);
console.log(JSON.stringify(arr));
console.log(util.inspect(arr, { compact: true, breakLength: 60, maxArrayLength: Infinity })); // breakLength: Infinity
// console.log(your_custom_array_format_method(arr));
[
[
59, 2, 71, 94, 43, 15, 83,
85, 41, 52, 89, 67, 62, 49,
15, 1, 26, 71, 94, 60
],
[
37, 42, 68, 78, 52, 95, 66,
61, 22, 38, 54, 73, 70, 14,
46, 57, 83, 87, 86, 35
]
]
[[59,2,71,94,43,15,83,85,41,52,89,67,62,49,15,1,26,71,94,60],[37,42,68,78,52,95,66,61,22,38,54,73,70,14,46,57,83,87,86,35]]
[ [ 59, 2, 71, 94, 43, 15, 83, 85, 41, 52, 89, 67, 62, 49, 15, 1, 26, 71, 94, 60 ],
[ 37, 42, 68, 78, 52, 95, 66, 61, 22, 38, 54, 73, 70, 14, 46, 57, 83, 87, 86, 35 ] ]
np.set_printoptions(edgeitems=5, precision=3, suppress=True, linewidth=160, threshold=50)