User Guide

JavaScript syntax arrays 47
Sorting arrays
Arrays are sorted in alphanumeric order, with numbers being sorted before strings. Strings are
sorted according to their initial letters, regardless of how many characters they contain.
To sort an array:
• Use the Array object’s sort() method.
The following statements sort a non-sorted alphabetical array.
// JavaScript syntax
var oldArray = ["d", "a", "c", "b"];
oldArray.sort(); // results in a, b, c, d
The following statements sort a non-sorted alphanumeric array.
// JavaScript syntax
var oldArray = [6, "f", 3, "b"];
oldArray.sort(); // results in 3, 6, b, f
Sorting an array results in a new sorted array.
Creating multidimensional arrays
You can also create multidimensional arrays that enable you to work with the values of more than
one array at a time.
In the following example, the first two statements create the separate arrays
array1 and array2.
The third statement creates a multidimensional array and assigns it to
mdArray. To access the
values in a multidimensional array, the fourth and fifth statements use brackets to access the
values in the array; the first bracket provides access to a specified array, and the second bracket
provides access to value at a specified index position in the array.
// JavaScript syntax
var array1 = new Array(5,10);
var array2 = [15,20];
var mdArray = new Array(array1, array2);
trace(mdArray[0][1]); // displays 10
trace(mdArray[1][0]); // displays 15