The Array Object in Javascript
Array Constructors
Array();
Array( size );
Array( element1, element2, ..., elementN);
Array Examples
var aMyArray = new Array();
var aMyArray = new Array( 20 );
var aMyArray = new Array( 1,5,2,20,99 );
var aMyArray = new Array( "Mon", "Tue", "Wed", "Thu", "Fri" );
Array Usage
//Adding elements to an array
for (x=0; x<MyCount; x++) {
aMyArray[x] = close(-x)/open(-x);
}
//Retrieving elements from an array
for (x=0; x<MyCount; x++) {
nMyValue = aMyArray[x];
debugPrint( "Value: " + nMyValue + "\n" );
}
Array Methods and Properties
concat(array2)
|
concatenates array2 into the array object
|
join(separator)
|
returns a string consisting ofall array elements concatenated with separator
|
length
|
returns the number of elements in the array
|
pop()
|
removes the last element from the array and returns that element
|
push()
|
adds one or more elements to the end of an array and returns the new length of the array
|
shift()
|
removes the first element from an array and returns that element
|
unshift()
|
adds one or more elements to the beginning of an array and returns the new array length
|
reverse()
|
reverses all of the elements in the array object
|
slice(start,end)
|
returns a section of the array from start to end
|
splice(start, quant, [item1,...,itemN])
|
changes the contents of an array, adding new elements while removing old elements
|
sort(sortFunc)
|
sorts the array using the user-defined sortFunc()
|
|