Array Class
Pollyfils for often used functionality for Arrays Copyright (c) 2014 ITSA - https://github.com/itsa New BSD License - http://choosealicense.com/licenses/bsd-3-clause/
Item Index
Methods
concatMerge
-
array
-
[prepend=false]
-
[clone=false]
-
[descriptors=false]
Merges array
into this array (appended by default).
contains
-
item
Checks whether an item is inside the Array. Alias for (array.indexOf(item) > -1)
Parameters:
-
item
Anythe item to seek
Returns:
whether the item is part of the Array
deepClone
-
[descriptors=false]
Returns a deep copy of the Array. Only handles members of primary types, Dates, Arrays and Objects.
Parameters:
-
[descriptors=false]
Boolean optionalwhether to use the descriptors when cloning
Returns:
deep-copy of the original
defineData
-
array
-
[clone=false]
Sets the items of array
to the instance. This will refill the array, while remaining the instance.
This way, external references to the array-instance remain valid.
empty
()
chainable
Empties the Array by setting its length to zero.
insertAt
-
item
-
index
-
[duplicate=false]
Inserts an item in the array at the specified position. If index is larger than array.length, the new item(s) will be appended.
If the item already exists, it will be moved to its new position, unless duplicate
is set true
observe
()
chainable
Observes changes of the instance. On any changes, the callback will be invoked. Uses a polyfill on environments that don't support native Array.observe.
The callback comes without arguments (native Array.observe does, but non-native doesn't) so, they cannot be used.
Will observer the complete array nested (deep).
remove
-
item
-
[arrayItem=false]
Removes an item from the array
Parameters:
replace
-
prevItem
-
newItem
Replaces an item in the array. If the previous item is not part of the array, the new item is appended.
Parameters:
-
prevItem
Anythe item to be replaced
-
newItem
Anythe item to be added
sameValue
-
refObj
Compares this object with the reference-object whether they have the same value. Not by reference, but their content as simple types.
Compares both JSON.stringify objects
Parameters:
-
refObj
Objectthe object to compare with
Returns:
whether both objects have the same value
shuffle
()
chainable
Shuffles the items in the Array randomly
unobserve
()
chainable
Un-observes changes that are registered with observe
.
Uses a polyfill on environments that don't support native Array.observe.