JavaScript Reference :: Array

There are a number of ways in which an array can be created, including a direct declaration. An Array can be created by passing a comma-delimited list to the Array constructor; for example, var oArray = new Array("black", "blue", "cyan", "green", "purple", "white"); will create an array of colors. If the parameter passed to the constructor method is a single digit e.g. var c = Array(7), the parameter will be treated as the length of the array (array elements will be null) unless JavaScript1.2 is the specified language, in which case the array will contain a single element whose value is the parameter passed.

Array

methods

void concat(array1, array2, ... array-n)
Adds the elements of the array(s) passed as parameters to the method to the array.
string join(separator)
Returns a string which contains the elements of the array delimited by the string passed as the separator.
object pop()
Returns the last element of the array and removes the element from the array.
int push(object)
Adds the object as the last element of the array and returns the (new) length of the array.
void reverse()
Reverses the order of the elements in the array.
object shift()
Returns the first element of the array and removes the element from the array.
Array slice(beginningIndex[, endingIndex])
Returns a subset of elements, identified by the beginning and ending indices provided, as an array. If no ending index is provided, the ending index defaults to the last element of the array.
void sort(compareFunction)
Sorts the elements of the array using the function specified.
Array splice(beginningIndex, elementsToRemove[, replacement1[, replacement-n]])
Returns a subset of elements, identified by the beginning index and continuing for the number of elements specified to remove, similar to slice; however, unlike slice, splice allows you to specify the replacement(s) for the element(s) being removed.
object toSource()
Returns a literal representing the source code of the object e.g "function Object() { [native code] }" or "function Car(manufactuer, model, productionyear) { this.make = manufactuer; this.model = model; this.year = productionyear; }".
string toString()
Returns a string representing the object i.e. "[object Object]".
int unshift(object)
Prepends an element to the array and returns the new length of the array.
void unwatch(property)
Removes a previously set watchpoint.
								
object valueOf()
Returns the primitive value of the object e.g. "function Object() { [native code] }".
void watch(property, handlingFunction)
Calls the handlingFunction when the property is changed.
								

properties

constructor
The constructor method is the base method used to create an instance of the object.
index
If the array is created as the result of a Regular Expression match, this property will be set to the zero-based index of that match.
input
If the array is created as the result of a Regular Expression match, this property will contain the original string against which the match was made.
length
The number of elements contained in the array.
prototype
Exposes the prototype for the method or property of the object.

events