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.
The table()
method writes a table to the console.
You can sort the table by clicking the column names.
console.table(
tabledata, tablecolumns)
Parameter | Description |
tabledata | Required. The data to fill the table with. |
tablecolumns | Optional. An array with the names of the table columns. |
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 »
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).
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!