Sencha Documentation

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

Methods

 
clean( Array 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

Parameters

  • array : Array

Returns

  • Array   results
 
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. Simply a convenient, easy-to-remember method for Array.prototype.slice.call(array)

Parameters

  • array : Array
    The array

Returns

  • Array   The clone array
 
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
 
each( Array/NodeList/Mixed array, Function fn, Object scope ) : Boolean
Iterates an array calling the supplied function.
Iterates an array calling the supplied function.

Parameters

  • array : Array/NodeList/Mixed
    The array to be iterated. If this argument is not really an array, the supplied function is called once.
  • fn : Function
    The function to be called with each item. If the supplied function returns false, iteration stops and this method returns the current index. This function is called with the following 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 passed as the first argument to Ext.each.
  • scope : Object
    The scope (this reference) in which the specified function is executed. Defaults to the item at the current index within the passed array.

Returns

  • Boolean   See description for the fn parameter.
 
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.
 
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
 
forEach( Array array, Function fn, Object scope ) : Void
Executes the provided function (callback) once for each element present in the array. Note that this will delegate to...
Executes the provided function (callback) once for each element present in the array. Note that this will delegate to the native forEach method in Array.prototype if the current browser supports it. It doesn't support breaking out of the iteration by returning false in the callback function like Ext.Array.each. Use this method when you don't need that feature for a huge performance boost on modern browsers

Parameters

  • array : Array
    The array to loop through
  • fn : Function
    The function callback, to be invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.
  • scope : Object
    The scope (this reference) in which the specified function is executed.

Returns

  • Void
 
from( Array/Mixed value ) : Array
Converts a value to an array if it's not already an array
Converts a value to an array if it's not already an array

Parameters

  • value : Array/Mixed
    The value to convert to an array if it is defined and not already an array.

Returns

  • Array   array
 
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
 
indexOf( Array array, Mixed item, [Number from] ) : Number
Get the index of the provided item in the given array, a supplement for the missing Array.prototype.indexOf in Intern...
Get the index of the provided item in the given array, a supplement for the missing Array.prototype.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)
 
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
 
merge( Array array,... ) : Array
Merge multiple arrays into one with unique items
Merge multiple arrays into one with unique items

Parameters

  • array,... : Array

Returns

  • Array   merged
 
pluck( Array|NodeList arr, String prop ) : Array
Plucks the value of a property from each item in the Array Example: Ext.pluck(Ext.query("p"), "className"); // [el1.c...
Plucks the value of a property from each item in the Array Example:
Ext.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]

Parameters

  • arr : Array|NodeList
    The Array of items to pluck the value from.
  • prop : String
    The property name to pluck from each element.

Returns

  • Array   The value from each item in the Array.
 
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
 
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.
 
toArray( Iterable array, Number start, Number end ) : Array
Converts any iterable (numeric indices and a length property) into a true array Don't use this on strings. IE doesn't...
Converts any iterable (numeric indices and a length property) into a true array Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on. For strings, use this instead: "abc".match(/./g) => [a,b,c];

Parameters

  • array : Iterable
    the iterable object to be turned into a true Array.
  • start : Number
    a number that specifies where to start the selection.
  • end : Number
    a number that specifies where to end the selection.

Returns

  • Array   array
 
unique( Array array ) : Array
Returns a new array with unique items
Returns a new array with unique items

Parameters

  • array : Array

Returns

  • Array   results