Arrays are essentially variables that can hold more than one value. Both VBScript and JScript support arrays for most data types. This sample demonstrates how you can create and use arrays in ASP scripts.
Each element of an array is accessed by using an index. Thus, in the array A, A(0) refers to the first element, A(1) refers to the second element, and so on. Note that array elements in both VBScript and JScript are numbered starting at 0.
Arrays can be fixed-size, or dynamically sizable. In both VBScript and JScript, the variable name must be declared, and storage space must be allocated for a new array. This is accomplished by using the Dim statement in VBScript, and the new statement in JScript. If a specific size is explicitly stated, then the array is fixed-size; but if a specific size is omitted from the declaration, then the array is considered dynamically sizable.
This sample creates two arrays, aFixed, which is fixed-size, and aColors, which is dynamically sizable. The script then assigns specific string values to each element in the arrays, using the index notation ArrayName(Index) to access the appropriate element. The script then loops through each array by using a For loop, and displays the results in a table.
Note that dynamically sizable arrays are implicitly expanded in JScript, so as to include the highest element indexed in an assignment. VBScript, in contrast, requires that you explicitly resize the dynamic array with the ReDim statement.
The VBScript and JScript versions of this script are available in the IIS samples directory, at ...\asp\simple\Arrays_VBScript.asp and ...\asp\simple\Arrays_JScript.asp.