A set of useful static methods to deal with arrays; provide missing methods for older browsers.
Filter through an array and remove empty item as defined in Ext.isEmpty
@see Ext.Array.filter
Filter through an array and remove empty item as defined in Ext.isEmpty
@see Ext.Array.filter
results
Clone a flat array without referencing the previous one. Note that this is different from Ext.clone since it doesn't handle recursive cloning. It's simply a convenient, easy-to-remember method for Array.prototype.slice.call(array)
The array
The clone array
Checks whether or not the given array
contains the specified item
Checks whether or not the given array
contains the specified item
The array to check
The item to look for
True if the array contains the item, false otherwise
Perform a set difference A-B by subtracting all items in array B from array A.
Perform a set difference A-B by subtracting all items in array B from array A.
A
B
difference
Executes the specified function for each array element until the function returns a falsy value. If such an item is found, the function will return false immediately. Otherwise, it will return true.
Callback function for each item
Callback function scope
True if no false value is returned by the callback function.
Creates a new array with all of the elements of this array for which the provided filtering function returns true.
Creates a new array with all of the elements of this array for which the provided filtering function returns true.
Callback function for each item
Callback function scope
results
Recursively flattens into 1-d Array. Injects Arrays inline.
Recursively flattens into 1-d Array. Injects Arrays inline.
The array to flatten
The new, flattened array.
Iterates an array and invoke the given callback function for each item. Note that this will simply delegate to the native Array.prototype.forEach method if supported. It doesn't support stopping the iteration by returning false in the callback function like each. However, performance could be much better in modern browsers comparing with each
The array to iterate
The function callback, to be invoked these arguments:
item
: {Mixed} The item at the current index
in the passed array
index
: {Number} The current index
within the array
allItems
: {Array} The array
itself which was passed as the first argument(Optional) The execution scope (this
) in which the specified function is executed.
Converts a value to an array if it's not already an array; returns:
undefined
or null
The value to convert to an array if it's not already is an array
(Optional) newReference True to clone the given array and return a new reference if necessary, defaults to false
array
Push an item into the array only if the array doesn't contain it yet
Push an item into the array only if the array doesn't contain it yet
The array
The item to include
The passed array itself
Get the index of the provided item
in the given array
, a supplement for the
missing arrayPrototype.indexOf in Internet Explorer.
The array to check
The item to look for
(Optional) The index at which to begin the search
The index of item in the array (or -1 if it is not found)
Merge multiple arrays into one with unique items that exist in all of the arrays.
Merge multiple arrays into one with unique items that exist in all of the arrays.
,...
intersect
Creates a new array with the results of calling a provided function on every element in this array.
Creates a new array with the results of calling a provided function on every element in this array.
Callback function for each item
Callback function scope
results
Returns the maximum value in the Array
Returns the maximum value in the Array
The Array from which to select the maximum value.
(optional) a function to perform the comparision which determines maximization.
If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
maxValue The maximum value
Calculates the mean of all items in the array
Calculates the mean of all items in the array
The Array to calculate the mean value of.
The mean.
Returns the minimum value in the Array.
Returns the minimum value in the Array.
The Array from which to select the minimum value.
(optional) a function to perform the comparision which determines minimization.
If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
minValue The minimum value
Plucks the value of a property from each item in the Array. Example:
Ext.Array.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]
The Array of items to pluck the value from.
The property name to pluck from each element.
The value from each item in the Array.
Removes the specified item from the array if it exists
Removes the specified item from the array if it exists
The array
The item to remove
The passed array itself
Executes the specified function for each array element until the function returns a truthy value. If such an item is found, the function will return true immediately. Otherwise, it will return false.
Callback function for each item
Callback function scope
True if the callback function returns a truthy value.
Sorts the elements of an Array. By default, this method sorts the elements alphabetically and ascending.
Sorts the elements of an Array. By default, this method sorts the elements alphabetically and ascending.
The array to sort.
(optional) The comparison function.
The sorted array.
Calculates the sum of all items in the given array
Calculates the sum of all items in the given array
The Array to calculate the sum value of.
The sum.
Converts any iterable (numeric indices and a length property) into a true array.
function test() {
var args = Ext.Array.toArray(arguments),
fromSecondToLastArgs = Ext.Array.toArray(arguments, 1);
alert(args.join(' '));
alert(fromSecondToLastArgs.join(' '));
}
test('just', 'testing', 'here'); // alerts 'just testing here';
// alerts 'testing here';
Ext.Array.toArray(document.getElementsByTagName('div')); // will convert the NodeList into an array Ext.Array.toArray('splitted'); // returns ['s', 'p', 'l', 'i', 't', 't', 'e', 'd'] Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
the iterable object to be turned into a true Array.
(Optional) a zero-based index that specifies the start of extraction. Defaults to 0
(Optional) a zero-based index that specifies the end of extraction. Defaults to the last index of the iterable value
array