Array utility functions
Index
Methods
-
<static> UWA.Array.equals(array, compare) → {Boolean}
-
Test wether two arrays are equal. Deprecated in favor of
UWA.equals.Example
var isEquals = UWA.Array.equals([], []); // isEquals value is now `true` var isEquals = UWA.Array.equals([1], [1,2,3]); // isEquals value is now `false`Parameters
Name Type Description arrayArray an array or array-like object
compareArray Array need to compare
Returns
trueif Arrays have the sames values elsefalse.- Type
- Boolean
-
<static> UWA.Array.detect(array, iterator, context) → {*}
-
Find the first value using a test function iterator.
Example
var search = UWA.Array.detect([8, 5, 6, 3, 5], function (v,i) { return v < 5 }); // search value is 3Parameters
Name Type Description arrayArray an array or array-like object
iteratorFunction A function applied to the values of the array The function is called with the context passed as second argument, and the current value, the current index and this array as arguments. When this function return a truthy value, the iteration stops and the current array value is returned.
contextObject Object to use as
thisReturns
The first value of the array matching the iterator function, or undefined if none of the values matches.
- Type
- *
-
<static> UWA.Array.invoke(array, fn, parametters) → {Array}
-
Executes a provided method once per array object.
Example
var test = [' foo', ' bar ']; UWA.Array.invoke(test, 'trim').join(','); // returns "foo,bar" UWA.Array.invoke(document.body.getElements('.item'), 'hide'); // hides all .item elementsParameters
Name Type Description arrayArray an array
fnString Method to call on every objects
paramettersOther parametters passed to the method call
Returns
The list of the results of method call.
- Type
- Array
-
<static> UWA.Array.erase(array, item) → {Array}
-
Erase every item contained in the array. Original array is modified.
Example
var test = ['red', 'green', 'red']; UWA.Array.erase(test, 'red'); // returns ['green'] UWA.Array.erase(test, 'purple'); // returns ['red', 'green', 'red']Parameters
Name Type Description arrayArray an array
itemMixed An item potentially defined in the array
Returns
The original array modified
- Type
- Array