Today I Learned

A Hashrocket project

Ready to join Hashrocket? Find Openings here and apply today.

Logging data as a table in the console

I’m sure you’re already familiar with console.log() to debug, but did you know that there is a similar console.table() that is great for displaying arrays and objects?

Here are some examples,

Assuming you had an array of names

img

Assuming you had a person object

img

Assuming you had an array of person objects

img

There is also an optional columns parameter, which takes an array containing the names of columns you want to include in the output.

console.table(data)
console.table(data, columns)

Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.