Ext.Array

Files

A set of useful static methods to deal with arrays; provide missing methods for older browsers.

Defined By

Methods

Ext.Array
view source
( array ) : Array
Filter through an array and remove empty item as defined in Ext.isEmpty. ...

Filter through an array and remove empty item as defined in Ext.isEmpty.

See filter

Parameters

Returns

Ext.Array
view source
( array ) : Array
Clone a flat array without referencing the previous one. ...

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).

Parameters

Returns

Ext.Array
view source
( array, item ) : Boolean
Checks whether or not the given array contains the specified item. ...

Checks whether or not the given array contains the specified item.

Parameters

  • array : Array

    The array to check.

  • item : Object

    The item to look for.

Returns

  • Boolean

    true if the array contains the item, false otherwise.

Ext.Array
view source
( arrayA, arrayB ) : Array
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.

Parameters

Returns

Ext.Array
view source
( iterable, fn, [scope], [reverse] ) : Boolean
Iterates an array or an iterable value and invoke the given callback function for each item. ...

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

Parameters

  • iterable : Array/NodeList/Object

    The value to be iterated. If this argument is not iterable, the callback function is called once.

  • fn : Function

    The callback function. If it returns false, the iteration stops and this method returns the current index.

    Parameters

    • item : Object

      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

    Returns

    • Boolean

      Return false to stop iteration.

  • scope : Object (optional)

    The scope (this reference) in which the specified function is executed.

  • reverse : Boolean (optional)

    Reverse the iteration order (loop from the end to the beginning).

    Defaults to: false

Returns

  • Boolean

    See description for the fn parameter.

Ext.Array
view source
( array, index, removeCount ) : Array
Removes items from an array. ...

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).

Parameters

  • array : Array

    The Array on which to replace.

  • index : Number

    The index in the array at which to operate.

  • removeCount : Number

    The number of items to remove at index.

Returns

Ext.Array
view source
( array, fn, scope ) : Boolean
Executes the specified function for each array element until the function returns a falsy value. ...

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.

Parameters

  • array : Array
  • fn : Function

    Callback function for each item.

  • scope : Object

    Callback function scope.

Returns

  • Boolean

    true if no false value is returned by the callback function.

Ext.Array
view source
( array, fn, scope ) : Array
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.

Parameters

  • array : Array
  • fn : Function

    Callback function for each item.

  • scope : Object

    Callback function scope.

Returns

Ext.Array
view source
( array ) : Array
Recursively flattens into 1-d Array. ...

Recursively flattens into 1-d Array. Injects Arrays inline.

Parameters

  • array : Array

    The array to flatten

Returns

Ext.Array
view source
( array, fn, [scope] )
Iterates an array and invoke the given callback function for each item. ...

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

Parameters

  • array : Array

    The array to iterate.

  • fn : Function

    The callback function.

    Parameters

    • item : Object

      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.

  • scope : Object (optional)

    The execution scope (this) in which the specified function is executed.

Ext.Array
view source
( value, [newReference] ) : Array
Converts a value to an array if it's not already an array; returns: An empty array if given value is undefined or n...

Converts a value to an array if it's not already an array; returns:

  • An empty array if given value is undefined or null
  • Itself if given value is already an array
  • An array copy if given value is iterable (arguments, NodeList and alike)
  • An array with one item which is the given value, otherwise

Parameters

  • value : Object

    The value to convert to an array if it's not already is an array.

  • newReference : Boolean (optional)

    true to clone the given array and return a new reference if necessary.

    Defaults to: false

Returns

Ext.Array
view source
( array, item )
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.

Parameters

  • array : Array

    The array.

  • item : Object

    The item to include.

Ext.Array
view source
( array, item, [from] ) : Number
Get the index of the provided item in the given array, a supplement for the missing arrayPrototype.indexOf in Interne...

Get the index of the provided item in the given array, a supplement for the missing arrayPrototype.indexOf in Internet Explorer.

Parameters

  • array : Array

    The array to check.

  • item : Object

    The item to look for.

  • from : Number (optional)

    The index at which to begin the search.

Returns

  • Number

    The index of item in the array (or -1 if it is not found).

Ext.Array
view source
( array, index, items ) : Array
Inserts items in to an array. ...

Inserts items in to an array.

Parameters

  • array : Array

    The Array on which to replace.

  • index : Number

    The index in the array at which to operate.

  • items : Array

    The array of items to insert at index.

Returns

Ext.Array
view source
( array1, array2, etc ) : Array
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.

Parameters

Returns

Ext.Array
view source
( array, fn, scope ) : Array
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.

Parameters

  • array : Array
  • fn : Function

    Callback function for each item.

  • scope : Object

    Callback function scope.

Returns

Ext.Array
view source
( array, [comparisonFn] ) : Object
Returns the maximum value in the Array. ...

Returns the maximum value in the Array.

Parameters

  • array : Array/NodeList

    The Array from which to select the maximum value.

  • comparisonFn : Function (optional)

    a function to perform the comparison which determines maximization. If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1

Returns

  • Object

    maxValue The maximum value

Ext.Array
view source
( array ) : Number
Calculates the mean of all items in the array. ...

Calculates the mean of all items in the array.

Parameters

  • array : Array

    The Array to calculate the mean value of.

Returns

Ext.Array
view source
( array1, array2, etc ) : Array
Merge multiple arrays into one with unique items. ...

Merge multiple arrays into one with unique items.

union is alias for merge

Parameters

Returns

Ext.Array
view source
( array, [comparisonFn] ) : Object
Returns the minimum value in the Array. ...

Returns the minimum value in the Array.

Parameters

  • array : Array/NodeList

    The Array from which to select the minimum value.

  • comparisonFn : Function (optional)

    a function to perform the comparison which determines minimization. If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1

Returns

  • Object

    minValue The minimum value.

Ext.Array
view source
( array, propertyName ) : Array
Plucks the value of a property from each item in the Array. ...

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]

Parameters

  • array : Array/NodeList

    The Array of items to pluck the value from.

  • propertyName : String

    The property name to pluck from each element.

Returns

  • Array

    The value from each item in the Array.

Ext.Array
view source
( array, item ) : Array
Removes the specified item from the array if it exists. ...

Removes the specified item from the array if it exists.

Parameters

  • array : Array

    The array.

  • item : Object

    The item to remove.

Returns

  • Array

    The passed array itself.

Ext.Array
view source
( array, index, removeCount, [insert] ) : Array
Replaces items in an 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.

Parameters

  • array : Array

    The Array on which to replace.

  • index : Number

    The index in the array at which to operate.

  • removeCount : Number

    The number of items to remove at index (can be 0).

  • insert : Array (optional)

    An array of items to insert at index.

Returns

Ext.Array
view source
( array, begin, end ) : Array
Returns a shallow copy of a part of an array. ...

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().

Parameters

  • array : Array

    The array (or arguments object).

  • begin : Number

    The index at which to begin. Negative values are offsets from the end of the array.

  • end : Number

    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.

Returns

  • Array

    The copied piece of the array.

Ext.Array
view source
( array, fn, scope ) : Boolean
Executes the specified function for each array element until the function returns a truthy value. ...

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.

Parameters

  • array : Array
  • fn : Function

    Callback function for each item.

  • scope : Object

    Callback function scope.

Returns

  • Boolean

    true if the callback function returns a truthy value.

Ext.Array
view source
( array, [sortFn] ) : Array
Sorts the elements of an Array. ...

Sorts the elements of an Array. By default, this method sorts the elements alphabetically and ascending.

Parameters

  • array : Array

    The array to sort.

  • sortFn : Function (optional)

    The comparison function.

Returns

Ext.Array
view source
( array, index, removeCount ) : Array
Replaces items in an array. ...

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.

Parameters

  • array : Array

    The Array on which to replace.

  • index : Number

    The index in the array at which to operate.

  • removeCount : Number

    The number of items to remove at index (can be 0).

Returns

  • Array

    An array containing the removed items.

Ext.Array
view source
( array ) : Number
Calculates the sum of all items in the given array. ...

Calculates the sum of all items in the given array.

Parameters

  • array : Array

    The Array to calculate the sum value of.

Returns

Ext.Array
view source
( iterable, [start], [end] ) : Array
Converts any iterable (numeric indices and a length property) into a true array. ...

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

Parameters

  • iterable : Object

    the iterable object to be turned into a true Array.

  • start : Number (optional)

    a zero-based index that specifies the start of extraction.

    Defaults to: 0

  • end : Number (optional)

    a zero-based index that specifies the end of extraction.

    Defaults to: -1

Returns

Ext.Array
view source
( array1, array2, etc ) : Array
Merge multiple arrays into one with unique items. ...

Merge multiple arrays into one with unique items.

union is alias for merge

Parameters

Returns

Ext.Array
view source
( array ) : Array
Returns a new array with unique items. ...

Returns a new array with unique items.

Parameters

Returns