Array

Methods

each(arr, callback, scope) static

Alias for array.each

Parameters:

NameTypeDescription
arrArray

Array to use.

callbackObject

The callback to use.

scopeObject

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:

NameTypeArgumentDescription
callbackfunction

Function to execute on each value in the array, taking three arguments:

Properties
NameTypeDescription
element*

The current element being processed in the array.

indexNumber

The index of the current element being processed in the array.

arrayArray

The array that is iterated over.

thisArgObjectoptional 

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:

NameTypeDescription
arrArray

Array to use.

callbackObject

The callback to use.

scopeObject

The object to use as this when invoking the callback.

from(arr) → {Array} static

Wraps the given input with a new Array.

Parameters:

NameTypeDescription
arr*

Variable to wrap.

Returns:

Returns a new Array object.

isArray(obj) → {Boolean} static

Determines whether the passed value is an Array.

Parameters:

NameTypeDescription
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:

NameTypeDescription
arrArray

Array to push to.

separatorString

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:

NameTypeArgumentDescription
arr*repeatable 

Items to turn into array.

Returns:

Returns a new array object.

pluck(arr, key) → {Array} static

Alias for array.pluck.

Parameters:

NameTypeDescription
arrArray

Array to pluck.

keyString

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:

NameTypeDescription
arrArray

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:

NameTypeDescription
arrArray

Array to use.

startNumber

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.

endNumber

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:

NameTypeDescription
allowEmptyStringBoolean

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:

NameTypeDescription
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:

NameTypeArgumentDescription
targetNumber

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.

startNumberoptional 

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).

endNumberoptional 

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:

NameTypeDescription
arrArray

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:

NameTypeDescription
cbfunction

The function that is called for each item. Can stop the each loop by returning false.

Properties
NameTypeDescription
item*

Returns the item within the scope of cb.

indexString

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:

NameTypeArgumentDescription
callbackfunction

Function to test each element of the array. Return true to keep the element, false otherwise.

Properties
NameTypeDescription
value*

The current value that callback is invoked with.

indexNumber

The current index that callback is invoked with.

arrayArray

The array that is iterated over.

thisArgObjectoptional 

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:

NameTypeArgumentDefaultDescription
value*

Value to fill an array.

startNumberoptional 0

Start index, defaults to 0.

endNumberoptional 

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:

NameTypeArgumentDescription
callbackfunction

Function to test each element of the array. Return true to keep the element, false otherwise.

Properties
NameTypeDescription
value*

The current value that callback is invoked with.

indexNumber

The current index that callback is invoked with.

arrayArray

The array that is iterated over.

thisArgObjectoptional 

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:

NameTypeArgumentDescription
callbackfunction

Function to execute on each value in the array, taking three arguments:

Properties
NameTypeDescription
element*

The current element being processed in the array.

indexNumber

The index of the current element being processed in the array.

arrayArray

The array findIndex was called upon.

thisArgObjectoptional 

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:

NameTypeDescription
cbfunction

The function that is called for each item.

Properties
NameTypeDescription
item*

Returns the item within the scope of cb.

indexString

Returns the index within the scope of cb.

arrayString

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:

NameTypeArgumentDescription
searchElement*

The element to search for.

fromIndexNumberoptional 

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:

NameTypeDescription
value*

Value to search for.

Returns:

lastIndexOf(value) → {Integer}

Returns the last index for the given key, returns -1 if not found.

Parameters:

NameTypeDescription
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:

NameTypeArgumentDescription
callbackfunction

The function to invoke on each element.

Properties
NameTypeDescription
value*

The current value that callback is invoked with.

indexNumber

The current index that callback is invoked with.

arrayArray

The array that is iterated over.

thisArgObjectoptional 

The object to use as this when invoking the callback.

Returns:

The newly created array.

merge(arr) → {Array}

Returns a combined array

Parameters:

NameTypeDescription
arrvalue

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:

NameTypeDescription
keyString

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:

NameTypeArgumentDescription
callbackfunction

Function to execute on each element in the array, taking four arguments:

Properties
NameTypeDescription
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.

currentIndexNumber

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.

arrayArray

The array reduce was called upon.

initialValueObjectoptional 

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:

NameTypeArgumentDescription
callbackfunction

Function to execute on each element in the array, taking four arguments:

Properties
NameTypeDescription
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.

indexNumber

The index of the current element being processed in the array.

arrayArray

The array reduce was called upon.

initialValueObjectoptional 

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:

NameTypeArgumentDescription
callbackfunction

Function to test each element of the array. Return true to keep the element, false otherwise.

Properties
NameTypeDescription
value*

The current value that callback is invoked with.

indexNumber

The current index that callback is invoked with.

arrayArray

The array that is iterated over.

thisArgObjectoptional 

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.