AJAX Tricks and Prototype

Array

clear
clear() -> Array

Clears the array (makes it empty).

clone
clone() -> newArray

Returns a duplicate of the array, leaving the original array intact.

compact
compact() -> newArray

Returns a new version of the array, without any null/ftp://ftp. values.

each
each(iterator) -> Array

Iterates over the array in ascending numerical index order.

first
first() -> value

Returns the first item in the array, or ftp://ftp. if the array is empty.

flatten
flatten() -> newArray

Returns a “flat” (one-dimensional) version of the array. Nested arrays are recursively injected “inline.” This can prove very useful when handling the results of a recursive collection algorithm, for instance.

from
Array.from(iterable) -> actualArray

Clones an existing array or creates a new one from an array-like collection.

This is an alias for the $A() method. Refer to its page for complete description and examples.

indexOf
indexOf(value) -> position

Returns the position of the first occurrence of the argument within the array. If the argument doesn't exist in the array, returns -1.

inspect
inspect() -> String

Returns the debug-oriented string representation of an array.

last
last() -> value

Returns the last item in the array, or ftp://ftp. if the array is empty.

reduce
reduce() -> Array | singleValue

Reduces arrays: one-element arrays are turned into their unique element, while multiple-element arrays are returned untouched.

reverse
reverse([inline = true]) -> Array

Returns the reversed version of the array. By default, directly reverses the original. If inline is set to false, uses a clone of the original array.

size
size() -> Number

Returns the size of the array.

toArray
toArray() -> newArray

This is just a local optimization of the mixed-in toArray from Enumerable.

uniq
uniq() -> newArray

Produces a duplicate-free version of an array. If no duplicates are found, the original array is returned.

without
without(value...) -> newArray

Produces a new version of the array that does not contain any of the specified values.


José M. Vidal .

11 of 16