What is the console.table() function in JavaScript?
The console.table command is used to display tabular data as a table.
Syntax
console.table(data);
console.table(data,columns);
-
data: must be either an array or an object -
columns: an Array that contains the names of the columns
Implementation
console.table can be implemented in the following ways:
1. Array
If the data argument is an array, the index column will be incremented by one, with the starting value being 0.
// Now let the data be an array of fruitsconsole.table(["apples", "oranges", "bananas"]);
2. Object
If the data is an object, then the parameter acts as the values of column 1, while column 2 displays the values stored in the respective parameter.
// an object with String input parametersfunction Person(Name, Destination) {this.Name = Name;this.Destination = Destination;}const me = new Person("John", "London");console.table(me);
3. Two-dimensional array
If the data is a 2D Array, then the column names will be incremented in the same way as the index column values.
// an 2D Array Consisting of First and the Last Namesconst Humans = [["John", "Smith"], ["Jane", "Doe"], ["Emily", "Jones"]]console.table(Humans)