• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Arrays

An array is an ordered collection of data, indexed by number. We compared a simple variable to a mailbox (send mail to the “Smith Residence”). An array is like a set of numbered apartment mailboxes (send mail to the “A-List Apartments, #12”). The only difference is that array index numbers start at zero rather than one.[29] Here’s a declaration of an array of radius sizes for circles. This form initializes the array. The second statement sets the value of the last element of the array to 9. You access one of the “slots” of an array by putting its index number in square brackets. Figure C-3 shows the results after the code has finished.

var radiusSizes = new Array( 8.5, 6.4, 12.2, 7 );
radiusSizes[3] = 9;

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint