ITSE 1411 Beginning Web
Arrays JS Module 2 Discussion
Discussion
- Arrays
- A set of data represented by a single variable name.
- Used to store groups of data.
- Declare arrays using the array object
- var arrayName = new Array(number of elements);
- When referencing an array element, use the array name and the index (an element's numeric position within the array).
- The array position begins with 0. Therefore, the first element of the array is referenced arrayName[0];
- In JavaScript, you can add new elements to the array even when you declare the array of a different size. Warning: If you
have an array size of 10, and accidentally assign a value to array[59], you actually create 50 more array elements and
assign the 60th element (remember the 60th element is referenced as 59).
- Every array has a length property which, when used, returns the number of elements in an array. For example:
var arraySize = arrayName.length();
will tell you how many elements are in the array.