Skip to main content

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

InputExpressionResult
[1, 2, 3, 4]
chunk(@, 2)
[
[1, 2],
[3, 4]
]
[1, 2, 3, 4]
chunk(@, 3)
[[1, 2, 3], [4]]

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

InputExpressionResult
[0, 1, false, "false", 2, "", 3, null]
compact(@)
[1, "false", 2, 3]

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

InputExpressionResult
[
["a", "b"],
["c", "d"],
["e", "f"]
]
concat([0], [1], [2])
["a", "b", "c", "d", "e", "f"]
[[1], 2, [3], [[4]]]
concat([0], [1], [2], [3])
[1, 2, 3, [4]]

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

array1 (Array)
The first array to combine.
array2 (Array)
The secord array to combine.

Returns

(Array)
The new array with combined elements.

Examples

InputExpressionResult
{
"array1": ["a", "b"],
"array2": [1, 2, 3]
}
cross_join(array1, array2)
[
["a", 1],
["a", 2],
["a", 3],
["b", 1],
["b", 2],
["b", 3]
]
{
"array1": [],
"array2": [1, 2, 3]
}
cross_join(array1, array2)
[]
{
"array1": ["a", "b"],
"array2": [1, [2, 3]]
}
cross_join(array1, array2)
[
["a", 1],
["a", [2, 3]],
["b", 1],
["b", [2, 3]]
]

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

InputExpressionResult
[
[1, 2, 3],
[1, 2]
]
difference([0], [1])
[3]
[
[1, 2],
[1, 2, 3]
]
difference([0], [1])
[]
[
["one", "four", "three"],
["five", "seven"]
]
difference(
[0],
[1],
&length(left)==length(right)
)
["one"]

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

InputExpressionResult
[
[2.1, 1.2],
[2.3, 3.4]
]
difference_by([0], [1], &floor(@))
[1.2]
[[{ "x": 2 }, { "x": 1 }], [{ "x": 1 }]]
difference_by([0], [1], 'x')
[{ "x": 2 }]

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 is 1

Returns

(Array)
The slice of array.

Examples

InputExpressionResult
["a", "b", "c", "d", "e"]
drop(@)
["b", "c", "d", "e"]
["a", "b", "c", "d", "e"]
drop(@, 2)
["c", "d", "e"]
["a", "b", "c", "d", "e"]
drop(@, 5)
[]
["a", "b", "c", "d", "e"]
drop(@, 0)
["a", "b", "c", "d", "e"]

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 is 1

Returns

(Array)
The slice of array.

Examples

InputExpressionResult
["a", "b", "c", "d", "e"]
drop_right(@, 2)
["a", "b", "c"]

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

InputExpressionResult
[
{
"user": "Jim",
"active": true
},
{
"user": "Ted",
"active": false
},
{
"user": "Mike",
"active": true
}
]
drop_right_while(
@,
&value.active == true
)
[
{
"user": "Jim",
"active": true
},
{
"user": "Ted",
"active": false
}
]

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

InputExpressionResult
[
{
"user": "Jim",
"active": true
},
{
"user": "Ted",
"active": false
},
{
"user": "Mike",
"active": true
}
]
drop_while(
@,
&value.active == true
)
[
{
"user": "Ted",
"active": false
},
{
"user": "Mike",
"active": true
}
]

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

InputExpressionResult
[
{
"user": "Jim",
"active": true
},
{
"user": "Ted",
"active": false
},
{
"user": "Mike",
"active": true
}
]
find_index(
@,
&value.user == 'Mike'
)
2
[
{
"user": "Jim",
"active": true
},
{
"user": "Ted",
"active": false
},
{
"user": "Mike",
"active": true
}
]
find_index(
@,
&value.user == 'James'
)
-1

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

InputExpressionResult
[
{
"user": "Jim",
"active": true
},
{
"user": "Ted",
"active": false
},
{
"user": "Mike",
"active": true
}
]
find_last_index(
@,
&value.user == 'Mike'
)
2
[
{
"user": "Jim",
"active": true
},
{
"user": "Ted",
"active": false
},
{
"user": "Mike",
"active": true
}
]
find_last_index(
@,
&value.user == 'Mike',
1
)
-1

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

InputExpressionResult
[1, 2, 3, 4]
first(@)
1
[]
first(@)
null

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

InputExpressionResult
[1, [2, [3, [4]], 5]]
flatten(@)
[1, 2, [3, [4]], 5]
[[1], [null]]
flatten(@)
-- compare to
-- [[1], [null]] | []
[1, null]

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

InputExpressionResult
[1, [2, [3, [4]], 5]]
flatten_deep(@)
[1, 2, 3, 4, 5]

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

InputExpressionResult
[1, [2, [3, [4]], 5]]
flatten_depth(@, 1)
[1, 2, [3, [4]], 5]
[1, [2, [3, [4]], 5]]
flatten_depth(@, 2)
[1, 2, 3, [4], 5]

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

InputExpressionResult
[
["a", 1],
["b", 2]
]
from_pairs(@)
{
"a": 1,
"b": 2
}

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

InputExpressionResult
[
[
{ "id": 1, "name": "a" },
{ "id": 2, "name": "b" }
],
[
{ "id": 1, "value": "1" },
{ "id": 3, "value": "3" }
]
]
full_join([0], [1], &[0].id == [1].id)
[
[
{ "id": 1, "name": "a" },
{ "id": 1, "value": "1" }
],
[null, { "id": 3, "value": "3" }],
[{ "id": 2, "name": "b" }, null]
]

See also


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

InputExpressionResult
[1, 2, 1, 2, null]
index_of(@, 2)
1
[1, 2, 1, 2, null]
index_of(@, 2, 2)
3
[1, 2, 1, 2, null]
index_of(@, 2, -1)
-1
[1, 2, 1, 2, null]
index_of(@, null)
4

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

InputExpressionResult
[1, 2, 3]
initial(@)
[1, 2]

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

InputExpressionResult
[
[
{ "id": 1, "name": "a" },
{ "id": 2, "name": "b" }
],
[
{ "id": 1, "value": "1" },
{ "id": 3, "value": "3" }
]
]
inner_join([0], [1], &[0].id == [1].id)
[
[
{ "id": 1, "name": "a" },
{ "id": 1, "value": "1" }
]
]

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

InputExpressionResult
[
[2, 1],
[2, 3]
]
intersection([0], [1])
[2]
[
[
{ "name": "Bob", "amount": 10 },
{ "name": "Tom", "amount": 20 }
],
[
{ "name": "Bob", "amount": 30 },
{ "name": "Tim", "amount": 40 }
]
]
intersection(
[0],
[1],
&left.name == right.name
)
[{ "name": "Bob", "amount": 10 }]

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

InputExpressionResult
[
[2.1, 1.2],
[2.3, 3.4]
]
intersection_by(
[0],
[1],
&floor(@)
)
[2.1]
[
[
{ "name": "Bob", "id": 1 },
{ "name": "Tom", "id": 2 }
],
[
{ "name": "Bobby", "id": 1 },
{ "name": "Tim", "id": 3 }
]
]
intersection_by(
[0],
[1],
'id'
)
[
{
"name": "Bob",
"id": 1
}
]

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

InputExpressionResult
[1, 2, 3, 4]
join(@)
"1,2,3,4"
["a", "b", "c"]
join(@, '-')
"a-b-c"

last()

Gets the last element of array.

last(array)

Arguments

array (Array)
The array to query.

Returns

(Any)
The last element of array.

Examples

InputExpressionResult
[1, 2, 3]
last(@)
3

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

InputExpressionResult
[1, 2, 1, 2, null]
last_index_of(@, 2)
3
[1, 2, 1, 2, null]
last_index_of(@, 2, 2)
1

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

InputExpressionResult
[
[
{ "id": 1, "name": "a" },
{ "id": 2, "name": "b" }
],
[
{ "id": 1, "value": "1" },
{ "id": 3, "value": "3" }
]
]
left_join([0], [1], &[0].id == [1].id)
[
[
{ "id": 1, "name": "a" },
{ "id": 1, "value": "1" }
],
[{ "id": 2, "name": "b" }, null]
]

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

InputExpressionResult
["a", "b", "c", "d", "e"]
nth(@, 1)
"b"
["a", "b", "c", "d", "e"]
nth(@, -2)
"d"

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

InputExpressionResult
[1, 2, 3, 4]
reverse(@)
[4, 3, 2, 1]
"Live"
reverse(@)
"eviL"

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

InputExpressionResult
[
[
{ "id": 1, "name": "a" },
{ "id": 2, "name": "b" }
],
[
{ "id": 1, "value": "1" },
{ "id": 3, "value": "3" }
]
]
right_join([0], [1], &[0].id == [1].id)
[
[
{ "id": 1, "name": "a" },
{ "id": 1, "value": "1" }
],
[null, { "id": 3, "value": "3" }]
]

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

InputExpressionResult
[1, 2, 3, 4, 5]
slice(@, 1, 3)
[2, 3]

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

InputExpressionResult
[1, 2, 3, 4, 5]
tail(@)
[2, 3, 4, 5]

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

InputExpressionResult
[1, 2, 3, 4, 5]
take(@, 2)
[1, 2]

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

InputExpressionResult
[1, 2, 3, 4, 5]
take_right(@, 2)
[4, 5]

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. The predicate is invoked with three named arguments: value, index, array. Default value is &value
.

Returns

(Array)
The slice of array.

Examples

InputExpressionResult
[
{
"user": "Jim",
"active": true
},
{
"user": "Ted",
"active": false
},
{
"user": "Mike",
"active": false
}
]
take_right_while(
@,
&!(value.active)
)
[
{
"user": "Ted",
"active": false
},
{
"user": "Mike",
"active": false
}
]

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. The predicate is invoked with three named arguments: value, index, array. Default value is &value
.

Returns

(Array)
The slice of array.

Examples

InputExpressionResult
[
{
"user": "Jim",
"active": true
},
{
"user": "Ted",
"active": false
},
{
"user": "Mike",
"active": false
}
]
take_while(
@,
&value.active
)
[
{
"user": "Jim",
"active": true
}
]

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

InputExpressionResult
[
[1, 2],
[2, 2, 3]
]
union([0], [1])
[1, 2, 3]
[
[
{ "name": "Bob", "id": 1 },
{ "name": "Tom", "id": 2 }
],
[
{ "name": "Bobby", "id": 1 },
{ "name": "Tim", "id": 3 }
]
]
union(
[0],
[1],
&left.id == right.id
)
[
{ "name": "Bob", "id": 1 },
{ "name": "Tom", "id": 2 },
{ "name": "Tim", "id": 3 }
]

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

InputExpressionResult
[
[2.1, 1.2],
[2.3, 3.4]
]
union_by(
[0],
[1],
&floor(@)
)
[2.1, 1.2, 3.4]
[
[
{ "name": "Bob", "id": 1 },
{ "name": "Tom", "id": 2 }
],
[
{ "name": "Bobby", "id": 1 },
{ "name": "Tim", "id": 3 }
]
]
union_by(
[0],
[1],
&length(name)
)
[
{
"name": "Bob",
"id": 1
},
{
"name": "Bobby",
"id": 1
}
]

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. The comparator is invoked with two named arguments: left, right. Default value is &left == right

Returns

(Array)
The new duplicate free array.

Examples

InputExpressionResult
[1, 2, 3, 2, 3]
uniq(@)
[1, 2, 3]
[
{ "name": "Bob", "id": 1 },
{ "name": "Tom", "id": 2 },
{ "name": "Bobby", "id": 1 },
{ "name": "Tim", "id": 3 }
]
uniq(
@,
&left.id == right.id
)
[
{
"name": "Bob",
"id": 1
},
{
"name": "Tom",
"id": 2
},
{
"name": "Tim",
"id": 3
}
]

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. The iteratee is invoked with one argument: value. Default value is &@
.

Returns

(Array)
The new duplicate free array.

Examples

InputExpressionResult
[1.1, 1.2, 2.1]
uniq_by(@, &floor(@))
[1.1, 2.1]
[
{ "name": "Bob", "id": 1 },
{ "name": "Tom", "id": 2 },
{ "name": "Bobby", "id": 1 },
{ "name": "Tim", "id": 3 }
]
uniq_by(@, 'id')
[
{
"name": "Bob",
"id": 1
},
{
"name": "Tom",
"id": 2
},
{
"name": "Tim",
"id": 3
}
]

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

InputExpressionResult
[
["a", 1, true],
["b", 2, false]
]
unzip(@)
[
["a", "b"],
[1, 2],
[true, false]
]

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

InputExpressionResult
[
[1, 10, 100],
[2, 20, 200]
]
unzip_with(@, &sum(@))
[3, 30, 300]

See also


without()

Creates an array excluding all given values.

without(array, value1, [value2, ...])

Arguments

array (Array)
The array to inspect.
values (Any)
The values to exclude.

Returns

(Array)
The new array of filtered values.

Examples

InputExpressionResult
[2, 1, 2, 3]
without(@, 1, 2)
[3]

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

InputExpressionResult
[
[1, 2, 3],
[2, 4]
]
xor([0], [1])
[1, 3, 4]
[
[
{ "name": "Bob", "id": 1 },
{ "name": "Tom", "id": 2 }
],
[
{ "name": "Bobby", "id": 1 },
{ "name": "Tim", "id": 3 }
]
]
xor(
[0],
[1],
&left.id == right.id
)
[
{
"name": "Tom",
"id": 2
},
{
"name": "Tim",
"id": 3
}
]

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

InputExpressionResult
[
[2.1, 1.2],
[2.3, 3.4]
]
xor_by(
[0],
[1],
&floor(@)
)
[1.2, 3.4]
[
[
{ "name": "Bob", "id": 1 },
{ "name": "Tom", "id": 2 }
],
[
{ "name": "Bobby", "id": 1 },
{ "name": "Tim", "id": 3 }
]
]
xor_by(
[0],
[1],
'id'
)
[
{
"name": "Tom",
"id": 2
},
{
"name": "Tim",
"id": 3
}
]

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

InputExpressionResult
[
["a", "b"],
[1, 2],
[true, false]
]
zip([0], [1], [2])
[
["a", 1, true],
["b", 2, false]
]

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

props (Array)
The property identifiers.
values (Array)
The property values.

Returns

(Object)
The new object.

Examples

InputExpressionResult
[
["a", "b"],
[1, 2]
]
zip_object([0], [1])
{
"a": 1,
"b": 2
}

See also


zip_object_deep()

This function is like zip_object() except that it supports property paths.

zip_object_deep(props, values)

Arguments

props (Array)
The property identifiers.
values (Array)
The property values.

Returns

(Object)
The new object.

Examples

InputExpressionResult
[
["a.b[0].c", "a.b[1].d"],
[1, 2]
]
zip_object_deep([0], [1])
{
"a": {
"b": [{ "c": 1 }, { "d": 2 }]
}
}

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

InputExpressionResult
[
[1, 2],
[10, 20]
]
zip_with([0], [1])
[
[1, 10],
[2, 20]
]
[
[1, 2],
[10, 20]
]
zip_with([0], [1], &add([0],[1]))
[11, 22]

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

InputExpressionResult
[
[1, 2],
[10, 20],
[100, 200]
]
zip_all_with(@, &sum(@))
[111, 222]
[
[1, 2],
[10, 20, 30],
[100, 200, 300, 400]
]
zip_all_with(@, &sum(@))
[111, 222, 330, 400]