Packagecom.rubenswieringa.utils
Classpublic class ArrayTool

Provides additional functionality for Arrays.

See also

edit 2 Before modifying and/or redistributing this class, please contact Ruben Swieringa (ruben.swieringa


Public Methods
 MethodDefined by
  
adjustValues(array:Array, value:*, operator:String = "*"):Array
[static] Adjusts all values in an Array.
ArrayTool
  
copy(source:Array):Array
[static] Returns a shallow copy of an Array.
ArrayTool
  
getValueMatchIndex(array:Array, property:*, value:*):int
[static] Similar to ArrayUtil.getItemIndex(), this method searches an Array for an Object with a given property that has a certain value.
ArrayTool
Method detail
adjustValues()method
public static function adjustValues(array:Array, value:*, operator:String = "*"):Array

Adjusts all values in an Array.

Parameters
array:Array — Array whose values to adjust
 
value:* — Value with which to increase, decrease, multiply, or divide a value from array with
 
operator:String (default = "*") — Indicates how to adjust a value from array (addition, minus, multiplication, or division)

Returns
Array — Array with adjusted values

See also

copy()method 
public static function copy(source:Array):Array

Returns a shallow copy of an Array.

Parameters
source:Array — Array to be copied.

Returns
Array

See also

getValueMatchIndex()method 
public static function getValueMatchIndex(array:Array, property:*, value:*):int

Similar to ArrayUtil.getItemIndex(), this method searches an Array for an Object with a given property that has a certain value. Can also search for nested Objects.

Parameters
array:Array — Array to search.
 
property:* — Property or property-chain to try every item in the Array for. This parameter can either be a String (normal property), Array (property-chain), or numeric value (array index).
 
value:* — Value to be found.

Returns
int — Index of the item where the value was found on the end of the property chain.

Example
The following code returns 2:

var array:Array = [ {foo: {bar: 'value1'}}, {foo: {bar: 'value2'}}, {foo: {bar: 'value3'}} ];
var propChain:Array = ['foo', 'bar'];
var value:String = 'value3';
ArrayTool.getValueMatchIndex (array, propChain, value); // outputs 2