Extension Array

Description

The Array extension builds upon the existing JavaScript Array object, providing new methods as well as standardized ones. This extension ensures that the Array object has access to the latest methods as Defined by ECMA-262, 3rd edition, as well as the new Mozilla-based extensions.

When loaded, this extension looks to see if the methods Defined by ECMA-262 and Mozilla 1.8 already exist. If so, these methods are not overridden. For thoes browsers that don't support these methods natively, they will be added so developers can seemlessly use these methods as if natively implemented. Additionally, several non-standard methods are added to everyone's implementation for convenience.

Author:

Nicholas C. Zakas, http://www.nczonline.net/

Method Summary

void append(variant item[])
Appends any number of items to the end of the array.
Array clone()
Creates and returns a duplicate of the array.
boolean contains(variant item)
Determines if a given item is in the array.
boolean every(Function test)
Runs a test on each item in the array and returns the result: true if all items pass, false if not.
boolean every(Function test, Object base)
Runs a test on each item in the array and returns the result: true if all items pass, false if not.
Array filter(Function test)
Runs a test on each item in the array and returns an array with all items that passed the test.
Array filter(Function test, Object base)
Runs a test on each item in the array and returns an array with all items that passed the test.
void forEach(function test)
Runs a function on each item in the array.
void forEach(function test, Object base)
Runs a function on each item in the array.
int indexOf(variant item)
Returns the position of a given item in the array starting from the first item, -1 if not found.
int indexOf(variant item, int start)
Returns the position of a given item in the array starting from the given position, -1 if not found.
void insertAt(variant item, int pos)
Inserts an item into the given position.
void insertBefore(variant item, variant beforeItem)
Inserts an item before the given item.
int lastIndexOf(variant item)
Return the position of a given item in the array starting from the last item, -1 if not found.
int lastIndexOf(variant item, int start)
Return the position of a given item in the array starting from the given start position, -1 if not found.
Array map(Function exec)
Runs a function on each item in the array and returns an array with the results.
Array map(Function exec, Object base)
Runs a function on each item in the array and returns an array with the results.
variant pop()
Removes the last item in the array and return sit.
void push(variant item[])
Appends any number of items to the end of the array.
variant remove(variant item)
Removes the given item from the array and returns it.
variant removeAt(int pos)
Removes the item in the given position from the array and returns it.
variant shift()
Removes the first item in the array and returns it.
Array slice(int start, int stop)
Creates and returns a new array made up of the items between the given positions.
boolean some(Function test)
Runs a test on each item in the array and returns the result: true if at least one item passes the test, false if not.
boolean some(Function test, Object base)
Runs a test on each item in the array and returns the result: true if at least one item passes the test, false if not.
Array splice(int pos, int length)
Removes the item starting at the given position and ending with that position plus the length specified.
Array splice(int pos, int length, variant item[])
Removes the item starting at the given position and ending with that position plus the length specified.
variant sum()
Returns the sum of the items in the array.
variant sum(Function convert)
Runs a conversion function on each item in the array and returns the sum of these values.
variant sum(Function convert, Object base)
Runs a conversion function on each item in the array and returns the sum of these values.
void unshift(variant item[])
Prepends any number of items to the front of the array.

Method Detail

append

public void append(variant item[])

Appends any number of items to the end of the array.

Arguments:

Defined by:

ECMA-262, 3rd Edition


clone

public Array clone()

Creates and returns a duplicate of the array.

Returns:

An exact copy of the array.

Defined by:

Nicholas C. Zakas, http://www.nczonline.net


contains

public boolean contains(variant item)

Determines if a given item is in the array.

Arguments:

Returns:

A boolean value: true if the item is in the array, false if not.

Defined by:

Nicholas C. Zakas, http://www.nczonline.net


every

public boolean every(Function test)

Runs a test on each item in the array and returns true if all items pass the test.

Arguments:

Returns:

A boolean value: true if all items pass the test, false if not.

Defined by:

Mozilla 1.8


every

public boolean every(Function test, Object base)

Runs a test on each item in the array and returns true if all items pass the test.

Arguments:

Returns:

A boolean value: true if all items pass the test, false if not.

Defined by:

Mozilla 1.8


filter

public Array filter(Function test, Object base)

Runs a test on each item in the array and returns an array of all items that passed the test.

Arguments:

Returns:

An array of items that passed the test.

Defined by:

Mozilla 1.8


forEach

public void forEach(Function exec)

Runs a function on each item in the array.

Arguments:

Defined by:

Mozilla 1.8


forEach

public void foreach(Function exec, Object base)

Runs a function on each item in the array.

Arguments:

Defined by:

Mozilla 1.8


indexOf

public int indexOf(variant item)

Returns the position of the given item starting at the front of the array, -1 if not found.

Arguments:

Returns:

The position of the item in the array or -1 if not found.

Defined by:

Mozilla 1.8


indexOf

public int indexOf(variant item, int start)

Returns the position of the given item starting at the given position from the front of the array, -1 if not found.

Arguments:

Returns:

The position of the item in the array or -1 if not found.

Defined by:

Mozilla 1.8


insertAt

public void insertAt(variant item, int pos)

Inserts an item into the array at a given position.

Arguments:

Defined by:

Nicholas C. Zakas, http://www.nczonline.net/


insertBefore

public void insertBefore(variant item, variant beforeItem)

Inserts an item into the array before the given item.

Arguments:

Defined by:

Nicholas C. Zakas, http://www.nczonline.net/


lastIndexOf

public int lastIndexOf(variant item)

Returns the position of the given item starting at the back of the array, -1 if not found.

Arguments:

Returns:

The position of the item in the array or -1 if not found.

Defined by:

Mozilla 1.8


lastIndexOf

public int lastIndexOf(variant item, int start)

Returns the position of the given item starting at the given position from the back of the array, -1 if not found.

Arguments:

Returns:

The position of the item in the array or -1 if not found.

Defined by:

Mozilla 1.8


map

public Array map(Function exec)

Runs a function on each item in the array and returns an array of the results.

Arguments:

Returns:

An array of results based on the running of the function on each item.

Defined by:

Mozilla 1.8


map

public Array map(Function exec, Object base)

Runs a function on each item in the array and returns an array of the results.

Arguments:

Returns:

An array of results based on the running of the function on each item.

Defined by:

Mozilla 1.8


pop

public variant pop()

Removes the last item in the array and returns it.

Returns:

The item that was removed.

Defined by:

ECMA-262, 3rd Edition


push

public void push(variant item[])

Appends any number of items to the end of the array.

Arguments:

Defined by:

ECMA-262, 3rd Edition


remove

public variant remove(variant item)

Removes the given item from the array and returns it.

Arguments:

Returns:

The item that was removed.

Defined by:

Nicholas C. Zakas, http://www.nczonline.net/


removeAt

public variant removeAt(int pos)

Removes the item at the given position and returns it.

Arguments:

Returns:

The item that was removed.

Defined by:

Nicholas C. Zakas, http://www.nczonline.net/


shift

public variant shift()

Removes the first item in the array and returns it.

Returns:

The item that was removed.

Defined by:

ECMA-262, 3rd Edition


slice

public Array slice(int start, int stop)

Creates and returns a new array made up of the items between the given positions.

Arguments:

Returns:

An array with the corresponding values.

Defined by:

ECMA-262, 3rd Edition


some

public boolean some(Function test)

Runs a test on each item in the array and returns the result: true if at least one item passes the test, false if not.

Arguments:

Returns:

A boolean value: true if at least one item passes the test, false if not.

Defined by:

Mozilla 1.8


some

public boolean some(Function test, Object base)

Runs a test on each item in the array and returns the result: true if at least one item passes the test, false if not.

Arguments:

Returns:

A boolean value: true if at least one item passes the test, false if not.

Defined by:

Mozilla 1.8


splice

public Array splice(int pos, int length)

Removes the item starting at the given position and ending with that position plus the length specified.

Arguments:

Returns:

An array containing all of the items that were removed during the operation.

Defined by:

ECMA-262, 3rd Edition


splice

public Array splice(int pos, int length, variant item[])

Removes the item starting at the given position and ending with that position plus the length specified.

Arguments:

Returns:

An array containing all of the items that were removed during the operation.

Defined by:

ECMA-262, 3rd Edition


sum

public variant sum()

Returns the sum of the values in the array.

Returns:

Either a string (if the array contains at least one string or object) or a number (if all items are numbers).

Defined by:

Nicholas C. Zakas, http://www.nczonline.net/


sum

public variant sum(Function convert)

Runs a conversion function on each item in the array and returns the sum of these values.

Arguments:

Returns:

Either a string (if the array contains at least one string or object) or a number (if all items are numbers).

Defined by:

Nicholas C. Zakas, http://www.nczonline.net


sum

public variant sum(Function convert, Object base)

Runs a conversion function on each item in the array and returns the sum of these values.

Arguments:

Returns:

Either a string (if the array contains at least one string or object) or a number (if all items are numbers).

Defined by:

Nicholas C. Zakas, http://www.nczonline.net/


unshift

public void unshift(variant item[])

Prepends any number of items to the front of the array. This is the opposite of shift().

Arguments:

Defined by:

ECMA-262, 3rd Edition