Skip to content

Instantly share code, notes, and snippets.

@stevencombs
Created September 7, 2013 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencombs/6477376 to your computer and use it in GitHub Desktop.
Save stevencombs/6477376 to your computer and use it in GitHub Desktop.
Examples of Javascript array types and usage.
// Javascript Arrays
// Dr. Steven B. Combs, coding novice
// Define array
var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];
console.log(languages[2]); // Print third item in array
console.log(languages.length); // Print number of items in array
// Print contents of array a line at a time
for (var i = 0; i < languages.length; i++){
console.log(languages[i]);
}
// Define 2D array
var newArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
// 3D array positioning
// 1 2 3
// 4 5 6
// 7 8 9
// Define jagged array
var jagged = [[1, 2], [3, 4, 5], [6, 7, 8, 9]];
// Jagged array positioning
// 1 2
// 3 5 5
// 6 7 8 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment