Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
communitycreator

What is the console.table() function in JavaScript?

Bhanu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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 fruits
console.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 parameters
function 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 Names
const Humans = [["John", "Smith"], ["Jane", "Doe"], ["Emily", "Jones"]]
console.table(Humans)

RELATED TAGS

javascript
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring