在forloop中的NodeJs console.table

所以这个NodeJS模块叫做console.table,你可以在控制台里面添加表格。 以下是他们网站的一个例子:

// 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和代码是这样的:

 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 } ); } 

Ref: Array.prototype.push

然后你原来的例子没有采取2参数只有一个这样的

 console.table("", values); 

应该是可能的

 console.table(values);