Return to site

JAVASCRIPT TIP: console.table 👉 log an objects list in a table way

· fullstack

You're probably familiar with console.log() in JavaScript.

But did you know about console.table()?

It's a super easy way to get a quick overview of an array of objects 🔥

 

broken image

 

broken image

See example 👇

👨‍💻SNIPPET:

const simpsons = [

  { name: 'Homer', age: 36 },

  { name: 'Marge', age: 34 },

  { name: 'Bart', age: 10 },

  { name: 'Lisa', age: 8 },

  { name: 'Maggie', age: 1 }

];

console.table(simpsons);

👀CONSOLE OUTPUT:

PS C:\_dev\VVJS\TEST> node vv/consoleTable.js  

┌─────────┬──────────┬─────ˑ┐

│(index)ˑˑˑˑˑˑˑˑˑˑˑˑˑ│ˑˑnameˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑ│ˑageˑˑˑˑˑˑˑ│

├─────────┼──────────┼─────ˑ┤

│ˑˑˑˑ0ˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑ│'Homer'ˑˑˑˑˑˑˑˑˑˑˑˑˑˑ│ˑ36ˑˑˑˑˑˑˑˑˑ│

│ˑˑˑˑ1ˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑ│'Marge'ˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑ│ˑ34ˑˑˑˑˑˑˑˑˑ│

│ˑˑˑˑ2ˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑ│'Bart'ˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑ│ˑ10ˑˑˑˑˑˑˑˑˑ│

│ˑˑˑˑ3ˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑ│'Lisa'ˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑ│ˑ8ˑˑˑˑˑˑˑˑˑˑˑˑ│

│ˑˑˑˑ4ˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑˑ│ˑMaggie'ˑˑˑˑˑˑˑˑˑˑˑˑˑˑ│1ˑˑˑˑˑˑˑˑˑˑˑˑ│

└─────────┴──────────ˑ┴─────┘