Storing a list of names in an array of values

In this recipe we will learn how to use a standard data structure called an Array to store a list of names or values.

Getting ready

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.

How to do it...

Add items to an array. Allow or disallow the addition of duplicate items with a switch in the form.

<script type="text/javascript" ...

Get MooTools 1.3 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.