一行中的节点console.log()输出数组 [英] node console.log() output array in one line
本文介绍了一行中的节点console.log()输出数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用节点 v10.6.0
。
这是我的代码:
console.log([{a:1, b:2}, {a:1, b:2}, {a:1, b:2}])
console.log([{a:1, b:2}, {a:1, b:2}, {a:1, b:2}, {a:1, b:2}, {a:1, b:2}, {a:1, b:2}, {a:1, b:2}, {a:1, b:2}, {a:1, b:2}])
输出如下:
[ { a: 1, b: 2 }, { a: 1, b: 2 }, { a: 1, b: 2 } ]
[ { a: 1, b: 2 },
{ a: 1, b: 2 },
{ a: 1, b: 2 },
{ a: 1, b: 2 },
{ a: 1, b: 2 },
{ a: 1, b: 2 },
{ a: 1, b: 2 },
{ a: 1, b: 2 },
{ a: 1, b: 2 } ]
如何我将第二个数组的输出放在一行中,而不是散布到多行中。
How can I make the second array output in one line, instead of spreading to multiple lines.
推荐答案
尽管输出并不完全相同就像使用 console.log
一样,可以使用 JSON.stringify
将数组转换为字符串,然后打印它:
Although the output is not exactly the same as if console.log
is used, it's possible to use JSON.stringify
to convert the array to a string, then print it:
console.log(JSON.stringify(array))
但是它不能处理循环结构。
It cannot process circular structures, however.
这篇关于一行中的节点console.log()输出数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文