Skip to content

Commit

Permalink
Rework console.table() page
Browse files Browse the repository at this point in the history
  • Loading branch information
wbamberg committed Oct 25, 2024
1 parent 59d50a9 commit 9d1168d
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions files/en-us/web/api/console/table_static/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ console.table(data)
console.table(data, columns)
```

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

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.
- `data`

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 (first row is the labeled index).
- : The data to display. This must be either an array or an object. Each item in the array, or property in the object, is represented by a row in the table. The first column in the table is labeled `(index)` and its values are the array indices or the property names.

### Parameters
If the elements in the array, or properties in the object, are themselves arrays or objects, then their items or properties are enumerated in the row, one per column.

- `data`
- : The data to display. This must be either an array or an object.
- `columns`
- : An array containing the names of columns to include in the output.
Note that in Firefox, `console.table()` is limited to displaying 1000 rows, including the heading row.

- `columns` {{optional_inline}}
- : An array which can be used to restrict the columns shown in the table. It contains indices, if `data` is a table, or property names, if `data` is an object. The resulting table then includes only columns for items which match the given indices or names.

### Return value

None ({{jsxref("undefined")}}).

## Examples

### Collections of primitive types

The `data` argument may be an array or an object.
Expand Down Expand Up @@ -104,7 +106,7 @@ const maria = new Person("Maria", "Cruz");
console.table([tyrone, janet, maria]);
```

Note that if the array contains objects, then the columns are labeled with the property name.
If the array contains objects, then the columns are labeled with the property name.

| (index) | firstName | lastName |
| ------- | --------- | -------- |
Expand Down Expand Up @@ -155,10 +157,6 @@ console.table([tyrone, janet, maria], ["firstName"]);
| 1 | 'Janet' |
| 2 | 'Maria' |

### Sorting columns

You can sort the table by a particular column by clicking on that column's label.

## Specifications

{{Specifications}}
Expand Down

0 comments on commit 9d1168d

Please sign in to comment.