Array
Methods
each(arr, callback, scope) static
Alias for array.each
Parameters:
Name Type Description arr Array Array to use.
callback Object The callback to use.
scope Object The object to use as this when invoking the callback.
find(callback, thisArg) → {*} static
Return the value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned.
Parameters:
Name Type Argument Description callback function Function to execute on each value in the array, taking three arguments:
Properties
Name Type Description element * The current element being processed in the array.
index Number The index of the current element being processed in the array.
array Array The array that is iterated over.
thisArg Object optional The object to use as this when invoking the callback.
Returns:
A value in the array if an element passes the test; otherwise, undefined.
forEach(arr, callback, scope) static
Alias for array.forEach
Parameters:
Name Type Description arr Array Array to use.
callback Object The callback to use.
scope Object The object to use as this when invoking the callback.
from(arr) → {Array} static
Wraps the given input with a new Array.
Parameters:
Name Type Description arr * Variable to wrap.
Returns:
Returns a new Array object.
isArray(obj) → {Boolean} static
Determines whether the passed value is an Array.
Parameters:
Name Type Description obj * The object to be checked.
Returns:
true if the object is an {Array}, false otherwise.
join(arr, separator) → {String} static
Alias for array.join.
Parameters:
Name Type Description arr Array Array to push to.
separator String Specifies a string to separate each element of the array.
Returns:
The joined elements of the array.
of(arr) → {Array} static
Creates a new Array instance from arguments.
Parameters:
Name Type Argument Description arr * repeatable Items to turn into array.
Returns:
Returns a new array object.
pluck(arr, key) → {Array} static
Alias for array.pluck.
Parameters:
Name Type Description arr Array Array to pluck.
key String The key that needs to be looked for in the array.
Returns:
The newly created array.
push(arr, obj) → {Number} static
Alias for array.push.
Parameters:
Name Type Description arr Array Array to push to.
obj * The item to push into the array.
Returns:
The new length property of the array.
slice(arr, start, end) → {Array} static
Alias for array.slice
Parameters:
Name Type Description arr Array Array to use.
start Number Zero-based index at which to begin extraction. As a negative index, begin indicates an offset from the end of the sequence. slice(-2) extracts the last two elements in the sequence. If begin is undefined, slice begins from index 0.
end Number Zero-based index at which to end extraction. slice extracts up to but not including end. slice(1,4) extracts the second element through the fourth element (elements indexed 1, 2, and 3). As a negative index, end indicates an offset from the end of the sequence. slice(2,-1) extracts the third element through the second-to-last element in the sequence. If end is omitted, slice extracts through the end of the sequence (arr.length).
Returns:
Returns a shallow copy of a portion of the array into a new array object.
clean(allowEmptyString) → {Array}
Cleans the array from empty items.
Parameters:
Name Type Description allowEmptyString Boolean Allows empty strings.
Returns:
The cleaned array.
clone() → {Array}
Clones the array.
Returns:
The cloned array.
contains(value) → {Boolean}
Checks if the array contains the value.
Parameters:
Name Type Description value * The value that need to be found.
Returns:
True when the value is within the Array. False otherwise.
copyWithin(target, start, end) → {Array}
Shallow copies part of an array to another location in the same array and returns it, without modifying its size.
Parameters:
Name Type Argument Description target Number Zero based index at which to copy the sequence to. If negative, target will be counted from the end. If target is at or greater than arr.length, nothing will be copied. If target is positioned after start, the copied sequence will be trimmed to fit arr.length.
start Number optional Zero based index at which to start copying elements from. If negative, start will be counted from the end. If start is omitted, copyWithin will copy from the start (defaults to 0).
end Number optional Zero based index at which to end copying elements from. copyWithin copies up to but not including end. If negative, end will be counted from the end. If end is omitted, copyWithin will copy until the end (default to arr.length).
Returns:
The modified array.
diff(arr) → {Array}
Returns the difference between the object and the param (note: not vice versa).
Parameters:
Name Type Description arr Array The Array that need to be compared.
Returns:
The difference between the object and the param.
each(cb)
Loops over all the items in the array, but can be stopped by returning false in the cb.
Parameters:
Name Type Description cb function The function that is called for each item. Can stop the each loop by returning false.
Properties
Name Type Description item * Returns the item within the scope of cb.
index String Returns the index within the scope of cb.
erase() → {Array}
Sets the length of the array to 0
Returns:
The erased array.
every(callback, thisArg) → {Boolean}
Tests whether all elements in the array pass the test implemented by the provided function.
Parameters:
Name Type Argument Description callback function Function to test each element of the array. Return true to keep the element, false otherwise.
Properties
Name Type Description value * The current value that callback is invoked with.
index Number The current index that callback is invoked with.
array Array The array that is iterated over.
thisArg Object optional The object to use as this when invoking the callback.
Returns:
Returns true if the callback function returns true for all array elements; otherwise, false.
fill(value, start, end) → {Array}
Fills all the elements of an array from a start index to an end index with a static value.
Parameters:
Name Type Argument Default Description value * Value to fill an array.
start Number optional 0 Start index, defaults to 0.
end Number optional End index, defaults to this.length.
Returns:
The modified array.
filter(callback, thisArg) → {Array}
Creates a new array with all elements that pass the test implemented by the provided function.
Parameters:
Name Type Argument Description callback function Function to test each element of the array. Return true to keep the element, false otherwise.
Properties
Name Type Description value * The current value that callback is invoked with.
index Number The current index that callback is invoked with.
array Array The array that is iterated over.
thisArg Object optional The object to use as this when invoking the callback.
Returns:
The newly created array.
findIndex(callback, thisArg) → {Number}
Returns the index of the first element in the array that satisfies the provided testing function. Otherwise -1 is returned.
Parameters:
Name Type Argument Description callback function Function to execute on each value in the array, taking three arguments:
Properties
Name Type Description element * The current element being processed in the array.
index Number The index of the current element being processed in the array.
array Array The array findIndex was called upon.
thisArg Object optional The object to use as this when invoking the callback.
Returns:
An index in the array if an element passes the test; otherwise, -1.
forEach(cb)
Loops over all the items in the array.
Parameters:
Name Type Description cb function The function that is called for each item.
Properties
Name Type Description item * Returns the item within the scope of cb.
index String Returns the index within the scope of cb.
array String Returns the array on which cb in invoked.
includes(searchElement, fromIndex) → {Boolean}
Determines whether an array includes a certain element, returning true or false as appropriate.
Parameters:
Name Type Argument Description searchElement * The element to search for.
fromIndex Number optional The position in this array at which to begin searching for searchElement. A negative value searches from the index of array.length + fromIndex by asc. Defaults to 0.
Returns:
true if the searchElement is in the array, false otherwise.
indexOf(value) → {Number}
Returns the first index at which a given element can be found in the array, or -1 if it is not present.
Parameters:
Name Type Description value * Value to search for.
Returns:
lastIndexOf(value) → {Integer}
Returns the last index for the given key, returns -1 if not found.
Parameters:
Name Type Description value * The value that need to be found.
Returns:
The last index for the given key.
map(callback, thisArg) → {Array}
Creates a new array with the results of calling a provided function on every element in this array.
Parameters:
Name Type Argument Description callback function The function to invoke on each element.
Properties
Name Type Description value * The current value that callback is invoked with.
index Number The current index that callback is invoked with.
array Array The array that is iterated over.
thisArg Object optional The object to use as this when invoking the callback.
Returns:
The newly created array.
merge(arr) → {Array}
Returns a combined array
Parameters:
Name Type Description arr value The array that need to be combined with.
Returns:
The combined array.
pluck(key) → {Array}
Create a new array containing only one key of all objects.
Parameters:
Name Type Description key String The key that needs to be looked for in the array.
Returns:
The newly created array.
reduce(callback, initialValue) → {*}
Applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.
Parameters:
Name Type Argument Description callback function Function to execute on each element in the array, taking four arguments:
Properties
Name Type Description accumulator * The accumulator accumulates the callback's return values; it is the accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.
currentValue * The current element being processed in the array.
currentIndex Number The index of the current element being processed in the array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
array Array The array reduce was called upon.
initialValue Object optional Value to use as the first argument to the first call of the callback. If no initial value is supplied, the first element in the array will be used. Calling reduce on an empty array without an initial value is an error.
Returns:
The value that results from the reduction.
reduceRight(callback, initialValue) → {*}
Applies a function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value.
Parameters:
Name Type Argument Description callback function Function to execute on each element in the array, taking four arguments:
Properties
Name Type Description previousValue * The value previously returned in the last invocation of the callback, or initialValue, if supplied.
currentValue * The current element being processed in the array.
index Number The index of the current element being processed in the array.
array Array The array reduce was called upon.
initialValue Object optional Optional. Object to use as the first argument to the first call of the callback.
Returns:
The value that results from the reduction.
shuffle() → {Array}
Return a shuffled array.
Returns:
The shuffled array.
some(callback, thisArg) → {Boolean}
Tests whether some element in the array passes the test implemented by the provided function.
Parameters:
Name Type Argument Description callback function Function to test each element of the array. Return true to keep the element, false otherwise.
Properties
Name Type Description value * The current value that callback is invoked with.
index Number The current index that callback is invoked with.
array Array The array that is iterated over.
thisArg Object optional The object to use as this when invoking the callback.
Returns:
Returns true if the callback function returns true for any array element; otherwise, false.
unique() → {Array}
Returns a stripped version of the array where all double values are removed.
Returns:
The stripped array.