- Open console using
Cmd+Opt+J
or Ctrl+Shift+J
.
- Use
console.table()
to output an array of arrays, or array of objects in a sortable, tabular format. For example,
console.table([[10, true, "blue"],[5, false]])
- If the number of elements in each object is not equal, the table will display
undefined
in cells for which there is no data.
- There is an optional second argument which allows you to explicitly specify which columns to output.
console.table([
{population:8173194, country:"UK", elevation:"24m"},
{population:8336697, country:"USA", elevation:"10m"}
],["population", "country"])