Output Data as a Table
console.table()
can be used to output data from an array of arrays or a list of objects in a sortable, tabular format.
For example, console.table([[10, true, "blue"],[5, false]])
will output the following:
If the number of elements in each object is not equal, the table will display undefined
in cells for which there is no data.
To give the table custom column names, property names must be assigned to the elements in the object. Likewise, custom values for the (index)
column can be set by naming each set of properties.
There is an optional second argument which allows you to explicity specify which columns to output. console.table({"London":{population:8173194, country:"UK", elevation:"24m"},"New York":{population:8336697, country:"USA", elevation:"10m"}},["population", "country"])
will output the following.