Created
August 26, 2012 20:17
-
-
Save jpetto/3483317 to your computer and use it in GitHub Desktop.
JavaScript array example
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 coffees = ['Ethiopia', 'Burundi', 'Costa Rica', 'Guatemala']; | |
console.log(coffees.length); | |
console.log("My favorite coffee is from " + coffees[1] + "."); | |
// change the second coffee in the array | |
coffees[1] = 'Brazil'; | |
console.log(coffees); | |
console.log("My favorite coffee is from " + coffees[1] + "."); | |
// add a coffee to the end of the array | |
coffees[coffees.length] = 'El Salvador'; | |
// be a troublemaker and add a coffee at position 100 | |
coffees[100] = 'Rwanda'; | |
console.log(coffees.length); | |
console.log(typeof(coffees)); // object? augh! no! how does that help me? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment