HTML DOM console.table() Method
Definition and Usage
The console.table() method writes a table in the console view.
The first parameter is required, and must be either an object, or an array, containing data to fill the table.
Tip: When testing console methods, be sure to have the console view visible (press F12 to view the console).
Browser Support
The numbers in the table specify the first browser version that fully supports the method.
Method | |||||
---|---|---|---|---|---|
console.table() | Yes | 12 | 34 | Yes | Yes |
Syntax
console.table(tabledata, tablecolumns)
Parameter Values
Parameter | Type | Description |
---|---|---|
tabledata | Object or Array | Required. The data to fill the table with |
tablecolumns | Array | Optional. An array containing the names of the columns to be included in the table |
More Examples
Example
Using an object as the first parameter:
console.table({ firstname : "John", lastname : "Doe" });
Try it Yourself »
Example
Using an array of objects:
var car1 = { name : "Audi", model : "A4" }
var car2 = { name : "Volvo",
model : "XC90" }
var car3 = { name : "Ford", model : "Fusion" }
console.table([car1, car2, car3]);
Try it Yourself »
Example
Specifying that we only want to include the "model" column in the table:
var car1 = { name : "Audi", model : "A4" }
var car2 = { name : "Volvo",
model : "XC90" }
var car3 = { name : "Ford", model : "Fusion" }
console.table([car1, car2, car3], ["model"]);
Try it Yourself »