Utilities for working with collections.
Methods
-
<static> addArrayKey(array, key, value)
-
Adds a value to an array at the specified key. If the key is an integer, the value is gently inserted into the array at that key, shifting the values with higher indices further down the array.
Parameters:
Name Type Description array
Array the array to add an entry key
Object the key to add value
Object the value to add -
<static> clear(target)
-
Remove all of the properties of a collection.
Parameters:
Name Type Description target
Object the map to clear -
<static> clearArray()
-
Remove all of the entries from an Array.
-
<static> cloneArray(source) → {Array}
-
Returns a shallow copy of an array.
Parameters:
Name Type Description source
Array the source array Returns:
the newly-created array- Type
- Array
-
<static> copyInto(target, source, keyConverter) → {Object}
-
Shallow-copies all of the properties of source into target and return the target.
Parameters:
Name Type Description target
Object the destination collection source
Object the source collection keyConverter
Function an optional key mapping fuction to use that takes in the raw source key and returns a converted key for the target Returns:
the passed in target (modifications applied)- Type
- Object
-
<static> copyProperties(target, source, sourceKeys, keyConverter) → {Object}
-
Copy the properties with the specified keys from the source to the destination using the optional keyConverter to convert the source keys to target keys.
Parameters:
Name Type Description target
Object the destination collection source
Object the source collection sourceKeys
Array the keys to copy keyConverter
Function an optional key mapping fuction to use that takes in the raw source key and returns a converted key for the target Returns:
the passed in target (modifications applied) or null if no copy was performed- Type
- Object
-
<static> getKeyOf(collection, value) → {Object}
-
Returns the key of the value in the specified collection, or
undefined
if the value is not a member of this collection.Parameters:
Name Type Description collection
Object the collection value
Object the value to find its first key Returns:
the first key that corresponds to the specified value or undefined if not found- Type
- Object
-
<static> indexOf(array, object) → {Number}
-
Returns the index of the object in the array, or -1 if the array does not contain the object.
Parameters:
Name Type Description array
Array the array object
Object the object to look up Returns:
the first index found- Type
- Number
-
<static> isArray()
-
Returns true if the object is an Array.
-
<static> isEmpty(collection) → {Boolean}
-
Returns if a collection is empty.
Parameters:
Name Type Description collection
Object a collection object to test for empty Returns:
whether the collection is empty- Type
- Boolean
-
<static> lastIndexOf(array, object) → {Number}
-
Returns the last index of the object in the array, or -1 if the array does not contain the object.
Parameters:
Name Type Description array
Array the array object
Object the object to look up Returns:
the last index found- Type
- Number
-
<static> removeAll(targetCollection, removeCollection, outCollection) → {Object}
-
Removes all of the properties of removeCollection from targetCollection. targetCollection is unmodified if targetCollection is not the same object as outCollection. If outCollection is specified, then it is cleared and populated with the results of the removal. Otherwise, a new object is created to hold the results.
Parameters:
Name Type Description targetCollection
Object the target collection removeCollection
Object an optional removeCollection outCollection
Object an optional collection that gets cleared and populated with the results of the removal or elase a new object is created to hold the results Returns:
the outCollection (or new object) holding the- Type
- Object
-
<static> removeArrayKey(array, key)
-
Removes the key from the array list if it is an integer, and from the key's properties if it isn't.
Parameters:
Name Type Description array
Array the array to remove an entry key
Object the key to remove -
<static> removeArrayValue(array, value) → {Number}
-
Removes the first instance of the specified value from the Array and returns the key the value was associated with, moving all of the array indices down and returning the index of the removed value, or -1 if the value wasn't found.
Parameters:
Name Type Description array
Array the array to search when removing value value
Object the value to remove from array Returns:
Index of value in array, or -1 if value wasn't found- Type
- Number
-
<static> removeValue(collection, value) → {Object}
-
Removes the first instance of the specified value from the collection and returns the key the value was associated with.
Parameters:
Name Type Description collection
Object the collection value
Object the value to delete its first entry Returns:
the first key that corresponds to the specified value or undefined if not found- Type
- Object
-
<static> union(inUnion1, inUnion2, outUnion) → {Object}
-
Returns the union of two sets of properties. With the properties of inUnion2 taking precendence over those of inUnion1. If outUnion is specified, it will be used as the output container instead of a new object being created and returned. outUnion may be the same object as inUnion1 or inUnion2.
Parameters:
Name Type Description inUnion1
Object the first collection inUnion2
Object the second collection (with higher precedence) outUnion
Object the optional output container Returns:
the union- Type
- Object