This works very similar to
console.table(data) returns the data as a table. The argument for the table must be an array or an object. The function will log each element of the array, or property of the object, as a different row of the table. The first column of the table will automatically be the 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.
This is especially useful when returning an array of many objects, with different properties. If given the following array of beers, using
console.log(), represents the data like so.
const beers = [
brewery: 'Peak Organic',
brewery: 'Troegs Independent Brewing',
name: 'The Mad Elf',
brewery: 'Full Sail Brewing',
brewery: 'Left Hand Brewing Co.',
name: 'Wake Up Dead',
brewery: 'Gun Hill Brewing Co.',
name: 'Void of Light',
(5) [Object, Object, Object, Object, Object]
One can see the different properties of each object, but the tree view can be difficult to visualize. Using
console.table() with the same data creates the following table.
This works best with objects that have similar keys, because more properties keys would create more columns within the table.