繁体   English   中英

forloop中的NodeJs console.table

[英]NodeJs console.table in a forloop

因此,有一个称为console.table的NodeJS模块,您可以在其中基本上在控制台内添加表。 这是他们网站上的示例:

// call once somewhere in the beginning of the app
require('console.table');
console.table([
{
name: 'foo',
age: 10
}, {
name: 'bar',
age: 20
}
]);

// prints
name  age
----  ---
foo   10
bar   20

这仅仅是一个例子,我试图通过将其放入forloop中使其自动化,而我希望可以运行的forloop和代码是这样的:

var values = [
]

for(var l = 0;l<config.accounts.username.length;l++) {
    values.push([

        {
            username: "Number "+l,
            itemtype: "Hello",
            amount: 10
        }, {
            itemtype: "Hello",
            amount: 10
        }

    ]);
}
console.table("", values);

不幸的是,它不起作用,有人可以帮助我吗?

谢谢!

您正在将值数组推入数组-删除[]

for(var l = 0;l<config.accounts.username.length;l++) {
    values.push(    
        {
            username: "Number "+l,
            itemtype: "Hello",
            amount: 10
        }, {
            itemtype: "Hello",
            amount: 10
        }

    );
}

参考: Array.prototype.push

然后您的原始示例没有使用2个参数,而是只使用了一个,因此

console.table("", values);

应该是

console.table(values);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM