The console.table() method is used to print data in a tabular format to the web console. We can sort the table by clicking on the column’s names. In other words, this method is useful to describe an object or array of content in a human-friendly table.
It is used for debugging purposes if there is a complex nested object or an array of objects of the same type, most of the time we face difficulty in reading, understanding, and comparing objects. console.table() is here to help us.
This method takes the first mandatory argument as data, which should be either array or an object which will be shown as a table. And the second argument is an optional parameter which is the columns names of the table as columns.
The first column in the table will be shown as an index. If the provided data is an array, then its values will be the array indices. If provided data is an object, then its values will be the property names.
Please Note that in Firefox console.table() is limited to displaying 1000 rows and the first row is the labeled index.
Syntax: console.table(tabularData, columns);
- tabularData – This is the mandatory parameter, and contains data that should be either array or an object.
- columns – This is an optional parameter that contains the names of the table columns to include in the display.
What we discussed above is given in the below example.
Output: Press F12 and go to the Console section