console.table() In JavaScript Debugging

Introduction

Most of the time as a developer we will be using console.log to debug the JavaScript code. There are a lot of other console functions which makes our debugging life easier. In this blog, I’m going to explain what is the use of console.table() in JavaScript debugging.  

console.table()

Consider the code below “arr” variable contains the array of elements. 

var arr = ["one", "two", "three", "four"]
console.log(arr);

When the console.log it will show the array in browser console with format as given below. 

It looks good, but when your array grows it’s hard to check the array of element in this format. When you found more elements in the array try to use console.table instead of console.log. 

console.table will populate the data in a table view which is very easy to read. 

var arr = ["one", "two", "three", "four"]
console.table(arr);

An array of elements in console with table format. 

Array of objects 

var arrObj = [{
    name: "Alexa",
    age: 29,
    country: "United States",
    address: "#123"
}, {
    name: "Siri",
    age: 30,
    country: "United States",
    address: "#123"
}, {
    name: "Shaaniya",
    age: 30,
    country: "India",
    address: "#123"
}, ]
console.table(arrObj);

Happy Coding!!!