Files
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 filter
results
Iterates an array or an iterable value and invoke the given callback function for each item.
var countries = ['Vietnam', 'Singapore', 'United States', 'Russia'];
Ext.Array.each(countries, function(name, index, countriesItSelf) {
console.log(name);
});
var sum = function() {
var sum = 0;
Ext.Array.each(arguments, function(value) {
sum += value;
});
return sum;
};
sum(1, 2, 3); // returns 6
The iteration can be stopped by returning false in the function callback.
Ext.Array.each(countries, function(name, index, countriesItSelf) {
if (name === 'Singapore') {
return false; // break here
}
});
Ext.each is alias for Ext.Array.each
The value to be iterated. If this argument is not iterable, the callback function is called once.
The callback function. If it returns false
, the iteration stops and this method returns
the current index
.
The item at the current index
in the passed array
The current index
within the array
The array
itself which was passed as the first argument
Return false to stop iteration.
The scope (this
reference) in which the specified function is executed.
Reverse the iteration order (loop from the end to the beginning).
Defaults to: false
See description for the fn
parameter.
Removes items from an array. This is functionally equivalent to the splice method of Array, but works around bugs in IE8's splice method and does not copy the removed elements in order to return them (because very often they are ignored).
The Array on which to replace.
The index in the array at which to operate.
The number of items to remove at index.
The array passed.
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
.
true
if no false
value is returned by the callback function.
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
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.
true
to clone the given array and return a new reference if necessary.
Defaults to: false
array
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.
The index at which to begin the search.
The index of item in the array (or -1 if it is not found).
Returns the maximum value in the Array.
The Array from which to select the maximum value.
a function to perform the comparison which determines maximization. If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
maxValue The maximum value
Returns the minimum value in the Array.
The Array from which to select the minimum value.
a function to perform the comparison 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.
Replaces items in an array. This is functionally equivalent to the splice method of Array, but works around bugs in IE8's splice method and is often more convenient to call because it accepts an array of items to insert rather than use a variadic argument list.
The Array on which to replace.
The index in the array at which to operate.
The number of items to remove at index (can be 0).
An array of items to insert at index.
The array passed.
Returns a shallow copy of a part of an array. This is equivalent to the native
call Array.prototype.slice.call(array, begin, end)
. This is often used when "array"
is "arguments" since the arguments object does not supply a slice method but can
be the context object to Array.prototype.slice()
.
The array (or arguments object).
The index at which to begin. Negative values are offsets from the end of the array.
The index at which to end. The copied items do not include end. Negative values are offsets from the end of the array. If end is omitted, all items up to the end of the array are copied.
The copied piece of the array.
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
.
true
if the callback function returns a truthy value.
Replaces items in an array. This is equivalent to the splice method of Array, but works around bugs in IE8's splice method. The signature is exactly the same as the splice method except that the array is the first argument. All arguments following removeCount are inserted in the array at index.
The Array on which to replace.
The index in the array at which to operate.
The number of items to remove at index (can be 0).
An array containing the removed items.
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']
Ext.toArray is alias for Ext.Array.toArray
the iterable object to be turned into a true Array.
a zero-based index that specifies the start of extraction.
Defaults to: 0
a zero-based index that specifies the end of extraction.
Defaults to: -1