2017-02-23 3 views
2

이 NodeJS 모듈은 기본적으로 콘솔에 테이블을 추가 할 수있는 console.table이라는 모듈이 있습니다. 여기에 자신의 웹 사이트에서 예입니다for 루프의 NodeJs console.table

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

// 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 및 코드는 이것이다

불행히도, 작동하지 않습니다, 누군가가 도와 줄 수 있습니까?

감사합니다. 그것은 단지 그렇게 일을했다이 개 매개 변수를 didnt는 Array.prototype.push

그리고 원래 예 : -

답변

0

당신은 당신의 배열에 값의 배열을 추진하고있는 [ & ]

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

console.table(values); 
+0

감사합니다. –