Tuesday, 2 October 2018

node.js: console.table(tabularData[, properties]): logs table data

console.table(tabularData[, properties])
If the data is parsed in tabular format, then the data is logged in tabular format, else just log the data normally.

HelloWorld.js
console.table([ {
 "firstName" : "Krishna",
 "lastName" : 'Ponnam'
}, {
 "firstName" : 'PTR',
 "lastName" : "Nayan"
} ]);

C:\Users\krishna\Documents\nodejs\examples>node HelloWorld.js
┌─────────┬───────────┬──────────┐
│ (index) │ firstName │ lastName │
├─────────┼───────────┼──────────┤
│    0    │ 'Krishna' │ 'Ponnam' │
│    1    │   'PTR'   │ 'Nayan'  │
└─────────┴───────────┴──────────┘

You can specify the properties that are used to construct the table.

HelloWorld.js

console.table([ {
 "firstName" : "Krishna",
 "lastName" : 'Ponnam'
}, {
 "firstName" : 'PTR',
 "lastName" : "Nayan"
} ], [ "firstName" ]);


C:\Users\krishna\Documents\nodejs\examples>node HelloWorld.js
┌─────────┬───────────┐
│ (index) │ firstName │
├─────────┼───────────┤
│    0    │ 'Krishna' │
│    1    │   'PTR'   │
└─────────┴───────────┘


Previous                                                 Next                                                 Home

No comments:

Post a Comment