CMSC 122 Lecture 37: CMSC 122 - Lecture 37 - NOV 19
CMSC 122 verified notes
37/46View all
Document Summary
Today we are going to discuss about 2 dimensional arrays and how to go about creating them. With javascript"s support for literal arrays in modern browsers (this tutorial predates that), this tutorial can arguably be considered obsolete. Nevertheless, we look at how to manually add additional dimensions to a regular array in javascript, and specifically, how to create a custom 2 dimensional array. If nothing it illustrates a technique for extending prebuilt javascript objects on your own. Before we switch dimensions, lets first quickly review how to create "normal" arrays, and take it from there: The above creates an array with 3 "storage compartments". A two-dimensional array is created simply by building on a "normal" array. Constructing a two-dimensional array requires that we declare another array on top of each of the "stems" (myarray[0], myarray[1]). To start things off, lets first illustrate graphically how a two dimensional array is represented: