Logging JavaScript Objects using console.table

Console.log is a well-known method to log objects on the console. However, if you want to print the objects in a tabular format, console.table is a really handy way to achieve this.

In this video, you will learn exactly how to use console.table

Code

'use strict'
let person = {
name: "Tony Stark",
phone: "500-124-9900",
location: "California",
birthYear: 1972
}
console.table(person)

Full Transcript

0:00 Hello there. Harit here from bonsaiilabs. In today's short video, we will learn how to log object using console.table. I'm currently in Chrome developer tools and have opened up the console window. Next I will add a new object called person which contains four properties, name, phone, location, and birthYear. Now to print this object onto the console, one way is to use console.log and passing into person as the argument. Once you hit enter, it prints the object on the console and you have to click in order to find out what this object contains. The another method that you can use from console is known as table. It takes the argument so when you pass in person and hit enter, it returns a table where the first column displays all the keys of the object and the second column displays all the values associated to those keys and in fact you also get the object if you want to click around and find out what's inside it. console.table is a really handy method to print the objects in a nice way so that there is no need for you to click and find out what's inside the object. And that's it. If you like the video, consider subscribing us to receive more engaging content about JavaScript every single week. Until then, keep learning new skills and apply them regularly to become an expert programmer. See you next time.