DEV Community

tanzirulhuda
tanzirulhuda

Posted on

JavaScript Hack 1- Use of console.table()

JavaScript is really a cool language. It has some awesome features that we should know. In this article, we are gonna see something really cool which is maybe you didn't see before.

console.table()

This awesome method will help you to CSV or dictionary format data in a table.
It takes one mandatory data which is must be an array.It will return you a table of this array. Every element of the array will be a row of table.

Let's have a look of it-

// Store data in an array
var data = ['Mercedes', 'Tesla', 'Rolls Royce', 'BMW'];

//Output
console.table(data);
Enter fullscreen mode Exit fullscreen mode

Let's move forward. Now we're gonna display an object in this method.

// An array of object

function Car(brand, ceo){
    this.brand = brand;
    this.ceo = ceo;
}

const mercedes = new Car('Mercedes', 'Ola Källenius');
const tesla= new Car('Tesla', 'Elon Musk');
const rollsRoyce = new Car('Rolls Royce', 'Warren East');
const bmw= new Car('BMW', 'Harald Krüger');

//Output
console.table([mercedes, tesla, rollsRoyce, bmw])
Enter fullscreen mode Exit fullscreen mode

Isn't it cool? I hope you enjoy this. Feel free to leave a comment and also share & ❤️ it.

You can follow me:)
Twitter

Happy coding🧑‍💻!

Top comments (0)