Last Updated : 09 Jul, 2020
The
console.table() methodis 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:console.table(data, properties);Parameters:
This method accept two parameters as mentioned above and described below:
This method doesn't return anything but print the constructed table and log it. If it fails to parse the arguments into the table then it simply logs the arguments. Below examples illustrate the use of console.table() method in Node.js.
Example 1: Filename: app.js javascript
// 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"]
);
Run the app.js file using the following command:
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 javascript
// 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([]);
Run the app.js file using the following command:
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_propertiesRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4