Represents indexed vector (array) of values.
Creates new array object from arguments provided. Use as
var a = new Array(...);
Returns string - comma separated list of values
Returns string - comma separated list of values
Same as toString.
Returns brand new copy of the array. If deep === true then it does recursive, deep cloning.
Appends array by values. Returns last inserted element.
Removes first element of the array. Returns removed element.
Removes last element of the array. Returns removed element.
Inserts value at first array position. Returns the value.
Appends array by values. Returns the array.
Returns string with all elements of the array separated by the delimeter or comma
Reverses order of elements in the array in-place. Returns the array.
Returns new array consisting from elements of the array from start up to but not including end index.
This method:
Sorts elements of the array in ascending order. If the compareFunction provided it is used for comparing elements during sort. compareFunction shall accept two values in parameters and return -1, 0 or +1 as a result.
Get index of the value in array. If the value is not found returns the notfound value (-1 by default).
Get last index of the value in array. If the value is not found returns the notfound value (-1 by default).
Removes element at index. Returns removed element.
Tries to locate element by value in the array and removes it. Returns removed element.
This method creates a new array with the result of calling a provided callback function on every element in this array. If thisObject is provided then the callback will have it as this.
The callback function may accept following parameters: callback(currentValue, index, array)
where:
The map methoddoes not mutate the array on which it is called.
If the callback function ends with nothing (without explicit return) then the element will not go to resulting array (as when filter() method below returns false). Note: this a la filter() behavior is non standard.
Example:
var numbers = [1, 2, 3]; var squares = numbers.map(:el:el*el); // make new array of // squares of numbers // in original array. // squares will be [1, 4, 9] at this point.
( callback:function [, initialValue] ) : value
This method applies the function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value.
The callback function may accept following parameters: callback(previousValue, currentValue, index, array)
where:
The method returns result of last callback invocation. The methoddoes not mutate the array on which it is called.
Example, this fragment calculates sum of all elements in the array:
var total = [0, 1, 2, 3].reduce( :a, b: a + b ); // total is 6 at this point.
( callback: function [, thisObject] ) : array
This method calls the callbackfunction once for each element in the array, and constructs new array of all the values for whichthe callback returns true.
The callback function may accept following parameters:callback(currentValue, index, array)
where:
The filter methoddoes not mutate the array on which it is called.
Example, this code creates new array from elements of source array that are greater than 10:
var filtered = [12, 5, 8, 130, 44].filter(:el: el > 10); // filtered is [12, 130, 44] here
Calls predicate function for each element of the array until the predicate returns "truthy" value. Returns found element.
The predicate is a function with the following signature:
function (element:any [, index:integer [, arr: array ]] ) : true | false
where:
If thisArg is provided then it is passed as this variable into the predicate calls.
The function returns as found index and as the element and so it can be used as:
var (i,v) = someArr.find(:el: el.id == "foo" ); // value and index, or var v = someArr.find(:el: el.id == "foo" ); // just value
Calls predicate function for each element of the array until the predicate returns "truthy" value and returns true. If there is no element in the array for which the predicate is true then the method returns false.
The predicate is a function with the following signature:
function (element:any [, index:integer [, arr: array ]] ) : true | false
where:
If thisArg is provided then it is passed as this variable into the predicate calls.
Returns true if for each element in the array predicate is true. If there is any element in the array for which the predicate is false the method returns false.
The predicate is a function with the following signature:
function (element:any [, index:integer [, arr: array ]] ) : true | false
where:
If thisArg is provided then it is passed as this variable into the predicate calls.
Attaches observer to the array - function that is called when the array changes. The observer here is a function that has following signature:
function observer(changeDefinition) {}
where changeDefinition is tuple having following fields:
[0]
- symbol, one of:#add-range
(one or many elements added), #update-range
(one or many elements changed) or #delete-range
(elements were deleted);[1]
- array, the object that property was changed;[2]
- integer, range start, index of first changed elements;[3]
- integer, range end (exclusive);Detaches given observer function from the array.