Monday, February 18, 2013

JavaScript Arrays

var ar = new Array("one", "two", "three");
var firstItem = ar[1];

for (i in ar){
   document.write("Item " + i + " is " + ar[i] + "<br />");
}


  • Can contain different types in the same array
  • Can be nested ([1][0])
  • push: to add element to end of array
  • unshift: to add element to the beginning of array
  • pop: remove the last element; returns the element as well
  • concat: combine two or more arrays into one array
  • join: combine elements of an array into a string
  • indexOf(value):  find the index of the first element in the array that matches the value