Skip to content

Instantly share code, notes, and snippets.

@phantom42
Created February 22, 2013 04:44
Show Gist options
  • Save phantom42/5010778 to your computer and use it in GitHub Desktop.
Save phantom42/5010778 to your computer and use it in GitHub Desktop.
Loops in JavaScript - Extra Tricks
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