Array functions
Perform various traversal and mutation operations with arrays.
chunk()
Creates an array of elements split into groups the length of size
. If array
can't be split evenly, the final chunk will be the remaining elements.
chunk(array, [size])
Arguments
array
(Array)- The array to process.
size
(Number)- (Optional) The number of elements in each chunk. Default value is
1
Returns
- (Array)
- The new array of arrays.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
compact()
Removes all falsey values from the original array
of elements. Compact will filter out false
, null
, 0
, ""
, undefined
, NaN
.
compact(array)
Arguments
array
(Array)- The array to process.
Returns
- (Array)
- The new array with filtered values.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
concat()
Creates a new array of elements concatenating a target array
with additional arrays and/or values
.
concat(array, [values])
Arguments
array
(Array)- The array to process.
values
(Any)- (Optional) The values to concatenate with original array. It could be one or many arrays and/or values.
Returns
- (Array)
- The new array with concatenated elements.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
cross_join()
Creates a new array of paired elements by combining each element of array1
with each element of the array2
. This join type is also known as cartesian join.
cross_join(array1, array2)
Arguments
Returns
- (Array)
- The new array with combined elements.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
|
|
|
See also
difference()
Creates new array with values from array1
not included in the array2
. It accepts comparator
which defines how elements of the arrays are compared. The order of the result values is determined by the first array.
Aliases: difference_with()
difference(array1, array2, [comparator])
Arguments
array1
(Array)- The array to inspect.
array2
(Array)- The values to exclude.
comparator
(Expression)- (Optional) The expression invoked for each element of the arrays. The
comparator
is invoked with two named arguments:left
,right
. Default value is&left == right
Returns
- (Array)
- The new array of filtered values.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
|
|
|
See also
difference_by()
This function is similar to difference() except that it accepts iteratee
which is invoked for each element of array1
and array2
to generate the criterion by which they're compared. The order of the result values is determined by the array1
.
difference_by(array1, array2, [iteratee])
Arguments
array1
(Array)- The array to inspect.
array2
(Array)- The values to exclude.
iteratee
(Expression | String)- (Optional) The expression invoked for each element of the arrays. The
iteratee
expression is invoked with one argument:@
(current element). Default value is&@
.
Returns
- (Array)
- The new array of filtered values.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
difference_with()
Same as difference().
drop()
Creates a new array from the original array
with n
elements dropped from the beginning.
drop(array, [n])
Arguments
array
(Array)- The array to query.
n
(Number)- (Optional) The number of elements to drop in the original
array
. Default value is1
Returns
- (Array)
- The slice of
array
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
See also
drop_right()
Creates a new array from the original array
with n
elements dropped from the end.
drop_right(array, [n])
Arguments
array
(Array)- The array to query.
n
(Number)- (Optional) The number of elements to drop in the original
array
from the end. Default value is1
Returns
- (Array)
- The slice of
array
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
drop_right_while()
Creates a new array from the original array
with elements dropped from the end. Elements are dropped until the predicate
returns falsey.
drop_right_while(array, [predicate])
Arguments
array
(Array)- The array to query.
predicate
(Expression | Array | Object | String)- (Optional) The expression invoked for each iteration. The
predicate
is invoked with three named arguments:value
,index
,array
. Default value is&value
Returns
- (Array)
- The slice of
array
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
drop_while()
Is similar to drop_right_while(), but it creates a new array from the original array
with elements dropped from the beginning. Elements are dropped until the predicate
returns falsey.
drop_while(array, [predicate])
Arguments
array
(Array)- The array to query.
predicate
(Expression | Array | Object | String)- (Optional) The expression invoked for each iteration. The
predicate
is invoked with three named arguments:value
,index
,array
. Default value is&value
Returns
- (Array)
- The slice of
array
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
find_index()
Iterates over elements of array
, returning the index of the first element predicate
returns truthy for.
find_index(array, [predicate], [fromIndex])
Arguments
array
(Array)- The array to inspect.
predicate
(Expression | Array | Object | String)- (Optional) The expression invoked for each iteration. The
predicate
is invoked with three named arguments:value
,index
,array
. Default value is&value
fromIndex
(Number)- (Optional) The index to search from. Default value is
0
Returns
- (Number)
- The index of the found element, else
-1
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
find_last_index()
This functions is like find_index() except that it iterates over elements of array
from right to left.
find_last_index(array, [predicate], [fromIndex])
Arguments
array
(Array)- The array to inspect.
predicate
(Expression | Array | Object | String)- (Optional) The expression invoked for each iteration. The
predicate
is invoked with three named arguments:value
,index
,array
. Default value is&value
. fromIndex
(Number)- (Optional) The index to search from. Default value is
0
Returns
- (Number)
- The index of the found element, else
-1
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
first()
Returns the first element of an array
.
Aliases: head()
first(array)
Arguments
array
(Array)- The array to query.
Returns
- (Any)
- The first element of
array
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
flatten()
Flattens an array
for the one level deep.
flatten(array)
Arguments
array
(Array)- The array to flatten.
Returns
- (Array)
- The new flattened array.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
flatten_deep
Flattens an array
recursively.
flatten_deep(array)
Arguments
array
(Array)- The array to flatten.
Returns
- (Array)
- The new flattened array.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
flatten_depth()
Flattens an array
recursively up to depth
times.
flatten_depth(array, [depth])
Arguments
array
(Array)- The array to flatten.
depth
(Number)- (Optional) The maximum recursion depth. Default value is
1
Returns
- (Array)
- The new flattened array.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
from_pairs()
The inverse of to_pairs() this function returns an object composed from key-value pairs.
from_pairs(pairs)
Arguments
pairs
(Array)- The key-value pairs.
Returns
- (Object)
- The new object.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
full_join()
Creates a new array of paired elements by combining each element of array1
(left) with each element of the array2
(right). It accepts comparator
which defines how elements of the arrays are matched. If there is no matching element in either of the arrays, null is returned. The comparator
is invoked with an array of two arguments: (array1Value
, array2Value
).
full_join(array1, array2, comparator)
Arguments
array1
(Array)- The first array to join.
array2
(Array)- The second array to join.
comparator
(Expression)- The comparator expression invoked per each element to compare elements of arrays.
Returns
- (Array)
- The new array with combined elements.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
head()
Alias for first().
index_of()
Gets the index at which the first occurrence of value
is found in array
starting from fromIndex
. If fromIndex
is negative, it's used as the offset from the end of array
.
index_of(array, value, [fromIndex])
Arguments
array
(Array)- The array to inspect.
value
(Any)- The element to search for in the
array
fromIndex
(Number)- (Optional) The index to search from.
Returns
- (Number)
- The index of the matched value, else
-1
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
initial()
Gets all elements of an original array
except the last one.
initial(array)
Arguments
array
(Array)- The array to inspect.
Returns
- (Array)
- The slice of
array
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
inner_join()
Creates a new array of paired elements by combining matching elements of array1
(left) and array2
(right). It accepts comparator
which defines how elements of the arrays are matched. The comparator
is invoked with an array of two arguments: (array1Value
, array2Value
).
right_join(array1, array2, comparator)
Arguments
array1
(Array)- The first array to join.
array2
(Array)- The second array to join.
comparator
(Expression)- The comparator expression invoked per each element to compare elements of arrays.
Returns
- (Array)
- The new array with combined elements.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
intersection()
Creates an array of unique values that are included in the two original arrays. As a third argument, the function accepts comparator
for elements comparison. The order of result values are determined by the first array.
intersection(array1, array2, [comparator])
Arguments
array1
(Array)- The first array to inspect.
array2
(Array)- The second array to inspect.
comparator
(Expression)- (Optional) The expression invoked for each element of arrays. The
comparator
is invoked with two named arguments:left
,right
. Default value is&left==right
.
Returns
- (Array)
- The new array of intersecting values.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
intersection_by()
This function is like intersection() except that it accepts iteratee
which is invoked for each element of array1
and array2
to generate the criterion by which they're compared. The order and references of result values are determined by the array1
.
intersection_by(array1, array2, [iteratee])
Arguments
array1
(Array)- The first array to inspect.
array2
(Array)- The second array to inspect.
iteratee
(Expression | String)- (Optional) The expression invoked for each element of the arrays. The
iteratee
expression is invoked with one argument:@
(current element). Default value is&@
.
Returns
- (Array)
- The new array of intersecting values.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
intersection_with()
Alias for intersection().
join()
Converts all elements in array
into a string separated by separator
.
join(array, [separator])
Arguments
array
(Array)- The array to convert.
separator
(Expression)- (Optional) The element separator. Default value is
','
Returns
- (String)
- The joined string.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
last()
Gets the last element of array
.
last(array)
Arguments
array
(Array)- The array to query.
Returns
- (Any)
- The last element of
array
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
last_index_of()
This function is like index_of() except that it iterates over elements of array
from right to left.
last_index_of(array, value, [fromIndex])
Arguments
array
(Array)- The array to inspect.
value
(Any)- The element to search for in the
array
fromIndex
(Number)- (Optional) The index to search from. Default value is
length(array) - 1
Returns
- (Number)
- The index of the matched value, else
-1
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
left_join()
Creates a new array of paired elements by combining each element of array1
(left) with matching elements of the array2
(right). It accepts comparator
which defines how elements of the arrays are matched. null is used, if there is no matching element in array2
(right). The comparator
is invoked with an array of two arguments: (array1Value
, array2Value
).
left_join(array1, array2, comparator)
Arguments
array1
(Array)- The first array to join.
array2
(Array)- The second array to join.
comparator
(Expression)- The comparator expression invoked per each element to compare elements of arrays.
Returns
- (Array)
- The new array with combined elements.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
nth()
Gets the element at index n
of array
. If n
is negative, the nth element from the end is returned.
nth(array, [n])
Arguments
array
(Array)- The array to query.
n
(Number)- (Optional) The index of the element to return. Default value is
0
Returns
- (Any)
- The nth element of
array
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
reverse()
Reverses array
so that the first element becomes the last, the second element becomes the second to last, and so on.
reverse(array)
Arguments
array
(Array)- The array to modify.
Returns
- (Array)
- The reversed array.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
right_join()
Creates a new array of paired elements by combining matching elements of array1
(left) with each element of the array2
(right). It accepts comparator
which defines how elements of the arrays are matched. null is used, if there is no matching element in array1
(left). The comparator
is invoked with an array of two arguments: (array1Value
, array2Value
).
right_join(array1, array2, comparator)
Arguments
array1
(Array)- The first array to join.
array2
(Array)- The second array to join.
comparator
(Expression)- The comparator expression invoked per each element to compare elements of arrays.
Returns
- (Array)
- The new array with combined elements.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
slice()
Creates a slice of array
from start
up to, but not including, end
.
slice(array, [start], [end])
Arguments
array
(Array)- The array to slice.
start
(Number)- (Optional) The start position. Default value is
0
end
(Number)- (Optional) The end position. Default value is
length(array)
Returns
- (Array)
- The new sliced array.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
tail()
Gets all but the first element of array
.
tail(array)
Arguments
array
(Array)- The array to query.
Returns
- (Array)
- The new tailed array.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
take()
Creates a slice of array
with n
elements taken from the beginning.
take(array, [n])
Arguments
array
(Array)- The array to query.
n
(Number)- (Optional) The number of elements to take. Default value is
1
Returns
- (Array)
- The slice of
array
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
take_right()
Creates a slice of array
with n
elements taken from the end.
take_right(array, [n])
Arguments
array
(Array)- The array to query.
n
(Number)- (Optional) The number of elements to take. Default value is
1
Returns
- (Array)
- The new sliced
array
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
take_right_while()
Creates a slice of array
with elements taken from the end. Elements are taken until predicate
returns falsey.
take_right_while(array, [predicate])
Arguments
array
(Array)- The array to query.
predicate
(Expression | Array | Object | String)- (Optional) The expression invoked for each element of the
array
. Thepredicate
is invoked with three named arguments:value
,index
,array
. Default value is&value
.
Returns
- (Array)
- The slice of
array
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
take_while()
Creates a slice of array
with elements taken from the beginning. Elements are taken until predicate
returns falsey.
take_while(array, [predicate])
Arguments
array
(Array)- The array to query.
predicate
(Expression | Array | Object | String)- (Optional) The expression invoked for each element of the
array
. Thepredicate
is invoked with three named arguments:value
,index
,array
. Default value is&value
.
Returns
- (Array)
- The slice of
array
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
union()
Creates an array
of unique values, in order, from given array1
and array2
using comparator
for equality comparisons.
union(array1, array2, [comparator])
Arguments
array1
(Array)- The first array to inspect.
array2
(Array)- The second array to inspect.
comparator
(Expression)- (Optional) The expression invoked for each pair of element of arrays. The
comparator
is invoked with two named arguments:left
,right
. Default value is&left==right
.
Returns
- (Array)
- The new array of combined values.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
union_by()
This function is like union() except that it accepts iteratee
which is invoked for each element of array1
and array2
to generate the criterion by which uniqueness is computed. Result values are chosen from the first array in which the value occurs.
union_by(array1, array2, [iteratee])
Arguments
array1
(Array)- The first array to inspect.
array2
(Array)- The second array to inspect.
iteratee
(Expression | String)- (Optional) The expression invoked for each element of the arrays. The
iteratee
expression is invoked with one argument@
(current element). Default value is&@
.
Returns
- (Array)
- The new array of combined values.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
union_with()
Alias for union().
uniq()
Creates a duplicate-free version of an array
, using comparator
for equality comparisons, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array
.
uniq(array, [comparator])
Arguments
array
(Array)- The array to inspect.
comparator
(Expression)- (Optional) The expression invoked for each element of the
array
. Thecomparator
is invoked with two named arguments:left
,right
. Default value is&left == right
Returns
- (Array)
- The new duplicate free array.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
uniq_by()
This function is like uniq() except that it accepts iteratee
which is invoked for each element in array
to generate the criterion by which uniqueness is computed. The order of result values is determined by the order they occur in the array
.
uniq_by(array, [iteratee])
Arguments
array
(Array)- The array to inspect.
iteratee
(Expression | String)- (Optional) The expression invoked for each element of the
array
. Theiteratee
is invoked with one argument:value
. Default value is&@
.
Returns
- (Array)
- The new duplicate free array.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
uniq_with()
Alias for uniq().
unzip()
This method is like zip() except that it accepts an array
of grouped elements and creates an array regrouping the elements to their pre-zip configuration.
unzip(array)
Arguments
array
(Array)- The array of grouped elements to process.
Returns
- (Array)
- The new array of regrouped elements.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
unzip_with()
This function is like unzip() except that it accepts combinator
to specify how regrouped values should be combined.
unzip_with(array, [combinator])
Arguments
array
(Array)- The array of grouped elements to process.
combinator
(Expression)- (Optional) The expression to combine regrouped values. The
combinator
is invoked with an array of elements of each group. Default value is&@
Returns
- (Array)
- The new array of regrouped elements.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
without()
Creates an array
excluding all given values
.
without(array, value1, [value2, ...])
Arguments
Returns
- (Array)
- The new array of filtered values.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
xor()
Creates an array of unique values that is the symmetric difference of the given array1
and array2
. It accepts comparator
which is invoked to compare elements of arrays. The order of result values is determined by the order they occur in the arrays.
xor(array1, array2, [comparator])
Arguments
array1
(Array)- The first array to inspect.
array2
(Array)- The second array to inspect.
comparator
(Expression)- (Optional) The expression, invoked for each pair of elements of the arrays. The
comparator
is invoked with two named arguments:left
,right
. Default value is&left == right
Returns
- (Array)
- The new array of filtered values.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
xor_by()
This function is like xor() except that it accepts iteratee
which is invoked for each element of array1
and array2
to generate the criterion by which by which they're compared. The order of result values is determined by the order they occur in the arrays.
xor_by(array1, array2, [iteratee])
Arguments
array1
(Array)- The first array to inspect.
array2
(Array)- The second array to inspect.
iteratee
(Expression | String)- (Optional) The expression invoked for each element of the arrays. The
iteratee
expression is invoked with one argument:@
(current element). Default value is&@
.
Returns
- (Array)
- The new array of filtered values.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
xor_with()
Alias for xor().
zip()
Creates an array of grouped elements, the first of which contains the first elements of the given arrays
, the second of which contains the second elements of the given arrays
, and so on.
zip(array1 [, array2 [...])
Arguments
arrays
(Array[])- The arrays to process.
Returns
- (Array)
- The new array of grouped elements.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
zip_object()
This function is like from_pairs() except that it accepts two arrays, one of property identifiers and one of corresponding values.
zip_object(props, values)
Arguments
Returns
- (Object)
- The new object.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
zip_object_deep()
This function is like zip_object() except that it supports property paths.
zip_object_deep(props, values)
Arguments
Returns
- (Object)
- The new object.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See also
zip_with()
This function is like zip() except that it accepts combinator
to specify how grouped values should be combined.
zip_with(array1, array2, [combinator])
Arguments
array1
(Array)- The first array to inspect.
array2
(Array)- The second array to inspect.
combinator
(Expression)- (Optional) The expression to combine regrouped values. The
combinator
is invoked with an array of elements of each group. Default value is&@
Returns
- (Array)
- The new array of grouped elements.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
See also
zip_all_with()
This function is like zip_with() except that it groups elements from all the arrays in arrayOfArrays
. The combinator
is invoked with the array of all elements in a group: ([array1Item
, array2Item
, ...]).
zip_all_with(arrayOfArrays, [combinator])
Arguments
arrayOfArrays
(Array)- The array of arrays to inspect.
combinator
(Expression)- (Optional) The expression to combine grouped values. The
combinator
is invoked with the array of all elements in a group. Default value is&@
Returns
- (Array)
- The new array of grouped elements.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|