One Tip a Week: Try console.table()

This week’s tip of the week is about JavaScript’s console. Most of us are probably familiar with console.log(), console.warn(), console.error(), and maybe even console.dir(), but there’s another handy one, console.table().

console.table() lets you view arrays and objects in a clean table format, making it much easier to scan data than using console.log(). It’s especially nice when debugging lists of objects.

const users = [
  { name: 'Alice', age: 32 },
  { name: 'Bob', age: 28 },
]
console.table(users)

Here’s what it looks like in your browser dev tools:

Users in the users variable in tabular format

You can even combine this with log points so you don’t need to litter your code with console.table()s. Just note that it only works with browser log points. VS Code’s log points only support strings/expressions.

That’s it! Short and sweet. Until the next one!

Side note: I tested this as a preview email and no big text for That’s it! Short and sweet. Until the next one! this week. 😅 Not sure what happened there.