English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM console.table() method

 JavaScript Console Object

console.table();This method displays table data in the console in table form.

This method takes a mandatory parameterdata((must be an array or an object) and an additional optional parametercolumn.

The first column of the table will be marked as (index)

Ifdatais an array, then its value will be the array index.

IfdataIf it is an object, then its value will be the property name.

Syntax:

console.table(data, columns)
console.table(["Apples", "Oranges", "Bananas"]);
Test and see‹/›

Browser compatibility

All browsers fully support the console.table() method:

Method
console.table();IsIsIsIsIs

Parameter value

ParameterDescription
dataThe data to be displayed. This must be an array or an object
columnsAn array of column names to include in the output

More examples

dataParameters as an object:

function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
var me = new Person("Seagull", "Anna");
console.table(me);
Test and see‹/›

If the element or property of an array or object itself is an array or object, then enumerate its elements or properties in the line, one per column:

var people = [["Seagull", "Anna"], ["Ankit", "Kumar"], ["Rudra", "GI"]];
console.table(people);
Test and see‹/›

By default, console.table() lists all elements in each row. You can use the optionalcolumnsParameters to select the subset of columns to display:

function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
var Seagull = new Person("Seagull", "Anna");
var ankit = new Person("Ankit", "Kumar");
var rudra = new Person("Rudra", "GI");
console.table([Seagull, ankit, rudra], ['firstName']);
Test and see‹/›

 JavaScript Console Object