Created
February 22, 2013 04:44
-
-
Save phantom42/5010778 to your computer and use it in GitHub Desktop.
Loops in JavaScript - Extra Tricks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var table = [ | |
["Person", "Age", "City"], | |
["Sue", 22, "San Francisco"], | |
["Joe", 45, "Halifax"] | |
]; | |
var rows = table.length ; | |
for (var i = 0 ; i < rows ; i++) { | |
var output = '' ; | |
var cells = table[i].length ; | |
for (var j = 0 ; j < cells; j++) { | |
output += (j < cells - 1) ? table[i][j]+ ' ' : table[i][j] ; | |
} | |
console.log(output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment