Javascript: Arrays 1

An array is a collection of data and may contain strings, numbers, booleans, null, undefined, and functions.


var names = ["bill","sara","philip","stacy"];

We now have an array called names that contains four strings. We access that data with the items index number.


names[0] //bill
names[1] //sara
names[2] //philip
names[3] //stacy
/*to find out the number of items in our array we can use the
  length property*/
alert(names.length);

Note:An array index starts at 0 not 1.