For up to date documentation and features, visit http://docs.sencha.com/ext-js/4-0

## Sencha Documentation

# Ext.Array

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

Defined By

### Methods

Ext.Array
view source
clean( Array array) : Array

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

### Parameters

- array : Array

### Returns

- Array

  results

Ext.Array
view source
clone( Array array) : Array
Clone a flat array without referencing the previous one. Note that this is different from Ext.clone since it doesn't ...

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

- array : Array

  The array

### Returns

- Array

  The clone array

Ext.Array
view source
contains( Array array, Mixed 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 : Mixed

  The item to look for

### Returns

- Boolean

  True if the array contains the item, false otherwise

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

- array : Array

  A

- array : Array

  B

### Returns

- Array

  difference

Ext.Array
view source
every( Array array, Function fn, Object scope) : Boolean
Executes the specified function for each array element until the function returns a falsy value. If such an item is f...

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
filter( Array array, Function fn, Object 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

- Array

  results

Ext.Array
view source
flatten( Array array) : Array

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

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

### Parameters

- array : Array

  The array to flatten

### Returns

- Array

  The new, flattened array.

Ext.Array
view source
forEach( Array array, Function fn, Object scope) : void
Iterates an array and invoke the given callback function for each item. Note that this will simply delegate to the na...

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 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
- scope : Object

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

### Returns

- void

Ext.Array
view source
from( Array/Mixed value, Boolean 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 : Array/Mixed

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

- newReference : Boolean

  (Optional) newReference True to clone the given array and return a new reference if necessary, defaults to false

### Returns

- Array

  array

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

### Parameters

- array : Array

  The array

- item : Mixed

  The item to include

### Returns

- Array

  The passed array itself

Ext.Array
view source
indexOf( Array array, Mixed item, Number 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 : Mixed

  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
intersect( Array array) : 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

- array : Array

  ,...

### Returns

- Array

  intersect

Ext.Array
view source
map( Array array, Function fn, Object 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

- Array

  results

Ext.Array
view source
max( Array|NodeList array, [Function comparisonFn]) : Mixed

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 comparision which determines maximization.

                    If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1

### Returns

- Mixed

  maxValue The maximum value

Ext.Array
view source
mean( Array 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

- Number

  The mean.

Ext.Array
view source
merge( Array array) : Array

Merge multiple arrays into one with unique items. Alias to union.

Merge multiple arrays into one with unique items. Alias to union.

### Parameters

- array : Array

  ,...

### Returns

- Array

  merged

Ext.Array
view source
min( Array|NodeList array, [Function comparisonFn]) : Mixed

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 comparision which determines minimization.

                    If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1

### Returns

- Mixed

  minValue The minimum value

Ext.Array
view source
pluck( Array|NodeList array, String propertyName) : Array
Plucks the value of a property from each item in the Array. Example: Ext.Array.pluck(Ext.query("p"), "className"); /...

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
remove( Array array, Mixed 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 : Mixed

  The item to remove

### Returns

- Array

  The passed array itself

Ext.Array
view source
some( Array array, Function fn, Object scope) : Boolean
Executes the specified function for each array element until the function returns a truthy value. If such an item is ...

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
sort( Array array, [Function sortFn]) : Array

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.

### Parameters

- array : Array

  The array to sort.

- sortFn : Function

  (optional) The comparison function.

### Returns

- Array

  The sorted array.

Ext.Array
view source
sum( Array 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

- Number

  The sum.

Ext.Array
view source
toArray( Mixed iterable, Number start, Number end) : Array
Converts any iterable (numeric indices and a length property) into a true array. function test() { var args = Ext.A...

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']

### Parameters

- iterable : Mixed

  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 the last index of the iterable value

### Returns

- Array

  array

Ext.Array
view source
union : void

Alias to merge.

Alias to merge.

### Returns

- void

Ext.Array
view source
unique( Array array) : Array

Returns a new array with unique items

Returns a new array with unique items

### Parameters

- array : Array

### Returns

- Array

  results