diff --git a/doc/api/console.md b/doc/api/console.md index 55adfc1e83befd..72d80ab9e792ba 100644 --- a/doc/api/console.md +++ b/doc/api/console.md @@ -332,6 +332,47 @@ console.log('count:', count); See [`util.format()`][] for more information. +### console.table(tabularData[, properties]) + + +* `tabularData` {any} +* `properties` {string[]} Alternate properties for constructing the table. + +Try to construct a table with the columns of the properties of `tabularData` +(or use `properties`) and rows of `tabularData` and logit. Falls back to just +logging the argument if it can’t be parsed as tabular. + +```js +// These can't be parsed as tabular data +console.table(Symbol()); +// Symbol() + +console.table(undefined); +// undefined +``` + +```js +console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }]); +// ┌─────────┬─────┬─────┐ +// │ (index) │ a │ b │ +// ├─────────┼─────┼─────┤ +// │ 0 │ 1 │ 'Y' │ +// │ 1 │ 'Z' │ 2 │ +// └─────────┴─────┴─────┘ +``` + +```js +console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], ['a']); +// ┌─────────┬─────┐ +// │ (index) │ a │ +// ├─────────┼─────┤ +// │ 0 │ 1 │ +// │ 1 │ 'Z' │ +// └─────────┴─────┘ +``` + ### console.time(label)