Skip to content

Instantly share code, notes, and snippets.

@jpetto
Created August 26, 2012 20:17
Show Gist options
  • Save jpetto/3483317 to your computer and use it in GitHub Desktop.
Save jpetto/3483317 to your computer and use it in GitHub Desktop.
JavaScript array example
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