Created
September 7, 2013 17:14
-
-
Save stevencombs/6477376 to your computer and use it in GitHub Desktop.
Examples of Javascript array types and usage.
This file contains 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
// 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