DEV Community

Cover image for How to create tables in Console DevTools
HeyBaldur
HeyBaldur

Posted on

How to create tables in Console DevTools

The console.table() method displays tabular data as a table.

This function takes one mandatory argument data, which must be an array or an object, and one additional optional parameter columns.

It logs data as a table. Each element in the array (or enumerable property if data is an object) will be a row in the table.

The first column in the table will be labeled (index). If data is an array, then its values will be the array indices. If data is an object, then its values will be the property names. Note that (in Firefox) console.table is limited to displaying 1000 rows row is the labeled index).

If you have any questions please feel free to contact/follow me on twitter and I will be glad to help you out.
Also you can take a look at my Gitbooks and check them out, I am still working on them so please be pacient with the results. Also check all my repos in GitHub

function Person(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}

var john = new Person("John", "Smith");
var jane = new Person("Jane", "Doe");
var emily = new Person("Emily", "Jones");

console.table([john, jane, emily]);
Enter fullscreen mode Exit fullscreen mode

Or also you can create something like

var family = {};

family.mother = new Person("Jane", "Smith");
family.father = new Person("John", "Smith");
family.daughter = new Person("Emily", "Smith");

console.table(family);
Enter fullscreen mode Exit fullscreen mode

I hope it helps!
Happy coding! 👍👍👍

Top comments (0)