Chapter 3 DynaScript Predefined Objects
The Array
object
has these methods:
Array.join( separator )
Converts the elements of the array into strings which are then concatenated. If no separator is given, commas will separate the strings.
String object.
This example lists the elements of the Array
separated by the
"&" character:
<!--SCRIPT
myArray = new Array();
myArray[0] = "carrots";
myArray[1] = "corn";
myArray[2] = "green beans";
myArray[3] = "celery";
document.WriteLn( myArray.join( " & " ) );
-->
The output from this example is:
carrots & corn & green beans & celery
Array.reverse( )
Reverses the order of the elements in the array.
Array object.
This example reverses and displays the content of the myArray array:
<!--SCRIPT
myArray = new Array();
myArray[0] = "carrots";
myArray[1] = "corn";
myArray[2] = "green beans";
myArray[3] = "celery";
document.WriteLn( myArray.reverse());
-->
Array.sort( [compareFunction] )
Sorts the elements of an array. A compareFunction can optionally be used to sort the array or the default may be used. The compare function takes two arguments a, b. If
Array object.
This example sorts the array alphabetically and displays the results:
<!--SCRIPT
myArray = new Array();
myArray[0] = "carrots";
myArray[1] = "corn";
myArray[2] = "green beans";
myArray[3] = "celery";
document.WriteLn( myArray.sort() );
-->
Array.toString( )
Converts the elements of the array to concatenated strings, separated by commas.
String.
This example converts the array elements to strings and displays them:
<!--SCRIPT
myArray = new Array();
myArray[0] = "carrots";
myArray[1] = "corn";
myArray[2] = "green beans";
myArray[3] = "celery";
document.WriteLn( myArray.toString() );
-->
Copyright © 1999 Sybase, Inc. All rights reserved. |