r/JavaScriptTips • u/ronCYA • Jul 15 '19
Use console.table() to log arrays, objects and nodelists in an organised view
Instead of console.log() you can use:
console.table(list)// table of all items and all columnsconsole.table(list, ['columnX', 'columnY', 'columnZ')// table restricted to set columns (very useful for NodeLists)console.table(list, 'columnX')// table restricted to one column

Hit F12 and copy the below into the console:
console.table(document.querySelectorAll('a'), ['innerText', 'href'])
Try replacing 'a' with another tag
Click NodeList(number) at the bottom of the table and expand one of the nodes to see all the different columns you can specify
Docs: https://developer.mozilla.org/en-US/docs/Web/API/Console/table
Have fun!
10
Upvotes