-
Notifications
You must be signed in to change notification settings - Fork 0
array
Array centric methods
var objAsArray = $.array.cast(obj);
Returns an Object (NodeList, etc.) as an Array
@param {Object} obj Object to cast
@param {Boolean} key [Optional] Returns key or value, only applies to Objects without a length property
@return {Array} Object as an Array
Example
var objAsArray = $.array.cast(obj);
Clones an Array
@param {Array} obj Array to clone
@return {Array} Clone of Array
Prototype
Array.prototype.clone
Example
var arClone = myArray.clone();
Finds the index of arg(s) in instance
@param {Array} obj Array to search
@param {String} arg Comma delimited string of search values
@return {Mixed} Integer or an array of integers representing the location of the arg(s)
Prototype
Array.prototype.contains
Example
if (myArray.contains("someValue, anotherValue").length > 0) doSomething();
Finds the difference between array1 and array2
@param {Array} array1 Source Array
@param {Array} array2 Comparison Array
@return {Array} Array of the differences
Prototype
Array.prototype.diff
Example
var result = ["abc", "xyz"].diff(["abc"]); // result = ["xyz"]
Iterates obj and executes fn, parameters for fn are 'value', 'key'
@param {Array} obj Array to iterate
@param {Function} fn Function to execute on index values
@return {Array} Array
Prototype
Array.prototype.each
Example
myArray.each(function (i) { doSomething(i); });
Returns the first Array node
@param {Array} obj The array
@return {Mixed} The first node of the array
Prototype
Array.prototype.first
Example
var x = myArray.first();
Facade to indexOf for shorter syntax
@param {Array} obj Array to search
@param {Mixed} arg Value to find index of
@return {Number} The position of arg in instance
Prototype
Array.prototype.index
Example
if (myArray.index("someValue") > -1) doSomething();
Returns an Associative Array (Object) as an Indexed Array of values
@param {Array} obj Array to index
@return {Array} Indexed Array
Prototype
Array.prototype.indexed
Example
var result = $.array.indexed({abc:true, xyz:{hhh:[true, false]}}) // result = [true, true, false]
Finds the intersections between array1 and array2
@param {Array} array1 Source Array
@param {Array} array2 Comparison Array
@return {Array} Array of the intersections
Prototype
Array.prototype.intersect
Example
var result = ["abc", "xyz"].intersect(["abc"]); // result = ["abc"]
Returns the keys in an Associative Array (Object)
@param {Array} obj Array to extract keys from
@return {Array} Array of the keys
Prototype
Array.prototype.keys
Example
var result = $.array.keys({abc:true}); // result = ["abc"]
Returns the last node of the array
@param {Array} obj Array
@return {Mixed} Last node of Array
Prototype
Array.prototype.last
Example
var x = myArray.last();
Returns a range of indices from the Array
@param {Number} start Starting index
@param {Number} end Ending index
@returns {Array} Array of indices
Prototype
Array.prototype.range
Example
var result = ar.range(0, 4);
Removes indices from an Array without recreating it
@param {Array} obj Array to remove from
@param {Number} start Starting index
@param {Number} end [Optional] Ending index
@return {Array} Modified Array
Prototype
Array.prototype.remove
Example
["abc", "xyz"].remove("xyz"); // ["abc"]
Casts an Array to Object
@param {Array} ar Array to transform
@return {Object} New object
Prototype
Array.prototype.toObject
Example
var result = ["abc"].toObject(); // result = {0: "abc"}
Gets the total keys in an Associative Array
@param {Array} obj Array to find the length of
@return {Number} Number of keys in Array
Prototype
Array.prototype.total
Example
var myArray = [];
myArray.abc = true;
myArray.total(); // 1