Table
From FirebugWiki
Sebastianz (Talk | contribs) (Added description of syntax, hint for needing help and linked back to Command Line API) |
Sebastianz (Talk | contribs) m (Fixed source code of last example) |
||
| (One intermediate revision not shown) | |||
| Line 1: | Line 1: | ||
| - | |||
| - | |||
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 (see more at [http://www.softwareishard.com/blog/firebug/tabular-logs-in-firebug/ softwareishard.com]). | ||
| Line 7: | Line 5: | ||
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]] | ||
Latest revision as of 12:51, 18 July 2012
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 (see more at softwareishard.com).
Contents |
[edit] Syntax
table(data[, columns])
[edit] Parameters
[edit] data
Data to log.
This is either an object or an array. (required)
[edit] Columns
Array containing the names for the columns in the output table. (optional)
[edit] Examples
table([1, 2, 3])
This creates a table containing three rows. The first one will contain 1, the second 2 and the third 3. Because there was no column title defined, the column will be named Object Properties
>ou will get the same output via table({a: 1, b: 2, c: 3}).
table([[1, 2], [3, 4]])
This creates a table containing two rows with two columns. The first row will contain 1 and 2 and the second one 3 and 4. The columns will be named by their index, i.e. 0 and 1.
You will get the same output via table({a: [1, 2], b: [3, 4]}).
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);
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:
For more examples see the article at softwareishard.com.
