console.table
Shows an array of objects as a table in the browser console.
Available since: Web API
Syntax
console.table(data, columns)Parameters
| Parameter | Type | Description |
|---|---|---|
| data | Array | object | An array or object to show as a table. |
| columns | string[] | Optional. Which columns to show. |
Return value
undefinedReturns nothing.
Examples
A table of users (output in the browser console):
const users = [
{ name: 'Anna', age: 25 },
{ name: 'Oleg', age: 31 },
];
console.table(users);Output:
┌─────────┬────────┬─────┐
│ (index) │ name │ age │
├─────────┼────────┼─────┤
│ 0 │ 'Anna' │ 25 │
│ 1 │ 'Oleg' │ 31 │
└─────────┴────────┴─────┘Notes
Handy for inspecting server data. The example above does not run on this site: the table appears only in a real browser console (F12) or in a Node.js terminal.
See also
- console.log — Prints values to the console.
- console.dir — Shows an object as a tree of properties.
Related recipes
In the tutorial
- Debugging — How to find bugs in JavaScript: reading the error message, console.log and its variants, checking types, developer tools and debugger.