Console table()
Example
Write an array as a table in the console:
console.table(["Audi", "Volvo", "Ford"]);
Try it Yourself »
Write an object as a table in the console:
console.table({firstname:"John", lastname:"Doe"});
Try it Yourself »
More examples below.
Description
The table()
method writes a table to the console.
Note
You can sort the table by clicking the column names.
Syntax
console.table(tabledata, tablecolumns)
Parameters
Parameter | Description |
tabledata | Required. The data to fill the table with. |
tablecolumns | Optional. An array with the names of the table columns. |
More Examples
Using an array of objects:
const car1 = {name:"Audi", model:"A4"}
const car2 = {name:"Volvo", model:"XC90"}
const car3 = {name:"Ford", model:"Fusion"}
console.table([car1, car2, car3]);
Try it Yourself »
Only include the "model" column in the table:
const car1 = {name:"Audi", model:"A4"}
const car2 = {name:"Volvo", model:"XC90"}
const car3 = {name:"Ford", model:"Fusion"}
console.table([car1, car2, car3], ["model"]);
Try it Yourself »
Browser Support
console.table()
is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
console.table()
is not supported in Internet Explorer 11 (or earlier).