Don't Use Console.log to Log a List of Objects!

Mangabo Kolawole - May 17 '22 - - Dev Community

When debugging your JavaScript application, console.log() is one of the most valuable methods to log into the browser console for the value of an object or anything.

But it's pretty challenging to navigate when displaying a list of objects.

For example, let's console log this data.

const data = [
  {
    "_id": "628332c6b14a04d1708be802",
    "index": 0,
    "guid": "61ec3d19-f7f3-4083-8bef-b9042c881c79",
    "isActive": true
  },
  {
    "_id": "628332c61dc4ecd57ae4f6fd",
    "index": 1,
    "guid": "49ea2d62-afec-4f62-9eae-0890a94462e3",
    "isActive": true
  },
  {
    "_id": "628332c6391c257b04b3c574",
    "index": 2,
    "guid": "a7f2240b-5b9b-4786-8b9d-92307f313349",
    "isActive": true
  },
  {
    "_id": "628332c66e1d9b58e696e38f",
    "index": 3,
    "guid": "b52e0d56-28d8-418f-a30f-e431b7fcaa20",
    "isActive": true
  },
  {
    "_id": "628332c676d375dc108e0f28",
    "index": 4,
    "guid": "e37e0f56-1c35-4f59-bb12-eda874be49fb",
    "isActive": false
  }
]
Enter fullscreen mode Exit fullscreen mode

Screenshot from 2022-05-17 06-32-17.png

And now let's use console.table(data) instead.

Screenshot from 2022-05-17 06-33-46.png

The data is much more readable and navigable. You can learn more about console.table here.

Article posted using bloggu.io. Try it for free.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .