Command line tabular format

If you want to display tablular data on the browser, all you have to do is use a table. If you happen to want to display it in the terminal window (or in a pre tag), it becomes a little more difficult. Here is a little trick I use to display tabular data:

var space = "              "; // the spaces between columns
var words = ["name","address", "city","State","zipcode","phone"];
var input = ["Ibrahim Diallo","123 fake street","Los Angeles","California","10002","310-555-5555"];
var i, total = input.length;

for(i=0;i<total;i++) {

The output is:

name:          Ibrahim Diallo
address:       123 fake street
city:          Los Angeles
State:         California
zipcode:       10002
phone:         310-555-5555 

This method could be used to format data to look like the output in the command line (where white space matters).


There are no comments added yet.

Let's hear your thoughts

For my eyes only