Allows to log provided data using tabular layout. The method takes one required parameter that represents table-like data (array of arrays or list of objects). The optional <code>columns</code> parameter can be used to specify columns and/or properties to be logged (see more at [http://www.softwareishard.com/blog/firebug/tabular-logs-in-firebug/ softwareishard.com]).

+

Allows to log provided data using tabular layout. The method takes one required parameter that represents table-like data (array of arrays or list of objects). The optional <code>columns</code> parameter can be used to specify columns and/or properties to be logged.

+

+

This command is a shortcut for the [[console.table]] API.

== Syntax ==

== Syntax ==

Line 5:

Line 7:

table(data[, columns])

table(data[, columns])

</source>

</source>

-

-

== Parameters ==

-

=== data ===

-

Data to log.

-

-

This is either an object or an array. '''(required)'''

-

-

=== Columns ===

-

Array containing the names for the columns in the output table. (optional)

-

-

== Examples ==

-

<source lang="javascript">

-

table([1, 2, 3])

-

</source>

-

-

This creates a table containing three rows. The first one will contain <code>1</code>, the second <code>2</code> and the third <code>3</code>. Because there was no column title defined, the column will be named <em>Object Properties</em>

-

-

>ou will get the same output via <code>table({a: 1, b: 2, c: 3})</code>.

-

-

<source lang="javascript">

-

table([[1, 2], [3, 4]])

-

</source>

-

-

This creates a table containing two rows with two columns. The first row will contain <code>1</code> and <code>2</code> and the second one <code>3</code> and <code>4</code>. The columns will be named by their index, i.e. <em>0</em> and <em>1</em>.

-

-

You will get the same output via <code>table({a: [1, 2], b: [3, 4]})</code>.

-

-

<source lang="javascript">

-

function Person(firstName, lastName, age)

-

{

-

this.firstName = firstName;

-

this.lastName = lastName;

-

this.age = age;

-

}

-

-

var family = {};

-

family.mother = new Person("Susan", "Doyle", 32);

-

family.father = new Person("John", "Doyle", 33);

-

family.daughter = new Person("Lily", "Doyle", 5);

-

family.son = new Person("Mike", "Doyle", 8);

-

-

console.table(family);

-

</source>

-

-

This creates a table containing four rows with three columns. The columns contain the first name, the last name and the age of each person:

-

-

[[file:tableOutputFamilyExample.png]]

-

-

For more examples see the [http://www.softwareishard.com/blog/firebug/tabular-logs-in-firebug/ article at softwareishard.com].

== See also ==

== See also ==

* [[Command Line API]]

* [[Command Line API]]

Revision as of 11:37, 18 November 2013

Allows to log provided data using tabular layout. The method takes one required parameter that represents table-like data (array of arrays or list of objects). The optional columns parameter can be used to specify columns and/or properties to be logged.