Node.js console.table() Method
Last Updated :
09 Jul, 2020
Improve
The console.table() method is an inbuilt application programming interface of the console module which is used to print the table constructed from it's parameters into the console.
Syntax:
javascript
Run the app.js file using the following command:
javascript
Run the app.js file using the following command:
console.table(data, properties);Parameters: This method accept two parameters as mentioned above and described below:
- data: Tabular data. An array of each row data that contains values for each column of that specific row.
- properties: It specifies the properties for constructing the table.
// Node.js program to demonstrate the
// console.table() method
// Accessing console module
const console = require('console');
// Calling console.table()
// without construction rule
console.table([
{ a: 1, b: 2 },
{ a: 3, b: 7, c: 'y' }
]);
// With construction rule
console.table([
{ a: 1, b: 2 },
{ a: 3, b: 7, c: 'y' }],
["a", "b"]
);
node app.jsOutput:
┌─────────┬───┬───┬─────┐ │ (index) │ a │ b │ c │ ├─────────┼───┼───┼─────┤ │ 0 │ 1 │ 2 │ │ │ 1 │ 3 │ 7 │ 'y' │ └─────────┴───┴───┴─────┘ ┌─────────┬───┬───┐ │ (index) │ a │ b │ ├─────────┼───┼───┤ │ 0 │ 1 │ 2 │ │ 1 │ 3 │ 7 │ └─────────┴───┴───┘Example 2: Filename: app.js
// Node.js program to demonstrate the
// console.table() method
// Accessing console module
const console = require('console');
// Calling console.table()
// fails to parse, so simply
// print the argument
console.table("arg");
// Blank table
console.table([]);
node app.jsOutput:
arg ┌─────────┐ │ (index) │ ├─────────┤ └─────────┘Note: The above program will compile and run by using the node filename.js command. Reference: https://nodejs.org/api/console.html#console_console_table_tabulardata_properties