July 2011
Intermediate to advanced
276 pages
5h 11m
English
In this recipe we will learn how to use a standard data structure called an Array to store a list of names or values.
To create an array, a storage element that holds a list of values, elements, or objects, we use the raw JavaScript Array object to define a literal array var myarray = [1, 2, 'my 3rd value'];. In our example, we first declare our array; it is in an empty state, then we call upon either raw JavaScript's push() array object method or MooTools' extension of the array native include(), based on the ternary output, to add our string value to the array.
Add items to an array. Allow or disallow the addition of duplicate items with a switch in the form.
<script type="text/javascript" ...