Skip to content
jshacks.dev
Debugging

Log a table of objects with console.table

Print an array of objects as an aligned table with console.table, choose columns with a second argument, and read the output in Node.js 24 or a browser.

1 min read
Summarize in AI

Logging an array of objects as [Object, Object] hides the data. console.table prints one row per item and one column per key, so you can compare values at a glance.

table.mjsJavaScript
const users = [
  { id: 1, name: "Ada" },
  { id: 2, name: "Linus" },
];

console.table(users);
console.table(users, ["name"]);
Text
┌─────────┬────┬─────────┐
│ (index) │ id │ name    │
├─────────┼────┼─────────┤
│ 0       │ 1  │ 'Ada'   │
│ 1       │ 2  │ 'Linus' │
└─────────┴────┴─────────┘
┌─────────┬─────────┐
│ (index) │ name    │
├─────────┼─────────┤
│ 0       │ 'Ada'   │
│ 1       │ 'Linus' │
└─────────┴─────────┘

The second argument limits the columns, which helps when each object has dozens of keys. Browsers draw a real table in the console instead of box characters and let you sort by clicking a header. See console.table in the Node.js docs.

Older Node.js releases center the cell text rather than left-aligning it, so the spacing can differ. The method also gets slow with thousands of rows, so log a slice.

Share

More snippets

Debugging

Group related logs with console.group

Indent related console output under a label with console.group and console.groupEnd, so interleaved logs from one request stay readable in Node.js 24.

1 min read
Debugging

Inspect an object with console.dir

Show nested objects beyond the default depth of two with console.dir and the depth option, instead of the [Object] placeholders console.log prints.

1 min read
Debugging

Debug a single Vitest test in VS Code

Run one Vitest file under the VS Code debugger with a launch configuration that passes the open file, so breakpoints in tests and source work. Vitest 3.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.