JavaScript:Arrays

Overview

 * An array is an object used to store a set of values under a single variable name

Creating an array

 * Array elements are referred to by an index staring at 0
 * Arrays are created using the new keyword


 * Data can be assigned to arrays by index or assignment (arrComputers1) or in one line (arrComputers2)

Online tutorials

 * JavaScript Array Object (w3schools, 2009a). http://www.w3schools.com/JS/js_obj_array.asp
 * JavaScript Array Object Reference. (w3schools, 2009b). http://www.w3schools.com/jsref/jsref_obj_array.asp

Simple array example (js7_01)
Example js7_01

Math and array example (js7_02)
Ref: Chapman (2008)

Example :.

Array split method
The array split method allows you to take a string and split it into an array based on a specified character. In the example following I will use the comma to split a name in lastname, firstname format and reverse the order. I have also added something a little special :)

Array.split .. example (jsArr_Split.htm)
Note: Just to show you how I have asked a unicode character to be displayed (\u2740) which is a flower. Unicode Inc (2009) gives pdf files for all the unicode characters (I used the Dingbats one for the flower).

Example :. ?????????????????????????????????????????? (upload) ?????????

Array multi-dimension
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]...)

As you can see, what we need to do is  declare a new array on top of each individual array "stem". The translation of this idea to actual codes, as you will see, is actually very simple

Multidimensional array example 1(js7_03)
Result

Example js7_03

Multidimensional array example 2(js7_04)
Result

Example js7_04