| array() An array can be said to be one or more pieces of data, which can be of any data type with different data types being allowed to coexist within the same array. Each piece of data residing in an array has an index number assigned to it. Using this number, you may refer to the piece of data corresponding to that index number. The index numbering starts at zero and goes up. All index numbers are integers, no exceptions, although there are a few instances where an indexed piece of data may be referred to with a string. Accessing an array requires the name of the array as well as the index number or string, in square brackets, as follows: cups[0] cups[teacup] In this example, we are accessing the 'cups' array. The value in the first array is 0, and the value in the second is 'teacup'. In order to add a piece of data to an array, you must assign a value to the next highest array index value, as follows: cups[cups.color] = "red" In this example, the new piece of data to the array was the color of the new cup, red. syntax: var anArray = new Array() var anArray = new Array(array size) var anArray = new Array(data1, data2, data3, etc) EXAMPLE anArray = new Array(red, green, blue, yellow); document.write("First make an array that contains four colors."); document.write("[0] = ", anArray[0] ); document.write("[1] = ", anArray[1] ); document.write("[2] = ", anArray[2] ); document.write("[3] = ", anArray[3] ); As you can see from the example above, an array named 'anArray' has been created with four pieces of information. Since there is data within the opening and closing parentheses of the statement, the array is not empty. These four data pieces, stuffed into the array in this way, are immediately available for use. Referencing the contents of the array is as simple as merely stating the name of the array, 'anArray', and the index number of the piece of data. You can see from the document.write statements how the index numbering works - red is represented by the index value '[0]', green is '[1]', blue is '[2]', and yellow is '[3]'. The Properties of the Array Object are: • length • prototype The Methods of the Array Object are • concat() • join() • pop() • push() • reverse() • shift() • slice() • sort() • unshift() |