Functions
Browse all available utility functions by category
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.
Example:
chunk(['a', 'b', 'c', 'd'], 2); // [['a', 'b'], ['c', 'd']]compact
Creates an array with all falsy values removed. The values false, null, 0, "", undefined, and NaN are falsy.
Example:
compact([0, 1, false, 2, '', 3]); // [1, 2, 3]concat
Creates a new array concatenating array with any additional arrays and/or values.
Example:
const array = [1];difference
Creates an array of array values not included in the other given arrays. The order and references of result values are determined by the first array.
Example:
difference([2, 1], [2, 3]); // [1]differenceBy
This method is like difference except that it accepts iteratee which is invoked for each element of array and values to generate the criterion by which they're compared.
Example:
differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [1.2]differenceWith
This method is like difference except that it accepts comparator which is invoked to compare elements of array to values.
Example:
const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];drop
Creates a slice of array with n elements dropped from the beginning.
Example:
drop([1, 2, 3]); // [2, 3]dropRight
Creates a slice of array with n elements dropped from the end.
Example:
dropRight([1, 2, 3]); // [1, 2]dropRightWhile
Creates a slice of array excluding elements dropped from the end. Elements are dropped until predicate returns falsey.
Example:
const users = [dropWhile
Creates a slice of array excluding elements dropped from the beginning. Elements are dropped until predicate returns falsey.
Example:
const users = [fill
Fills elements of array with value from start up to, but not including, end.
Example:
const array = [1, 2, 3];findIndex
Returns the index of the first element predicate returns truthy for instead of the element itself.
Example:
const users = [findLastIndex
This method is like findIndex except that it iterates over elements of collection from right to left.
Example:
const users = [first
Gets the first element of array.
Example:
first([1, 2, 3]); // 1flatten
Flattens array a single level deep.
Example:
flatten([1, [2, [3, [4]], 5]]); // [1, 2, [3, [4]], 5]flattenDeep
Recursively flattens array.
Example:
flattenDeep([1, [2, [3, [4]], 5]]); // [1, 2, 3, 4, 5]flattenDepth
Recursively flatten array up to depth times.
Example:
const array = [1, [2, [3, [4]], 5]];fromPairs
Returns an object composed from key-value pairs.
Example:
fromPairs([['a', 1], ['b', 2]]); // { 'a': 1, 'b': 2 }head
Gets the first element of array.
Example:
head([1, 2, 3]); // 1indexOf
Gets the index at which the first occurrence of value is found in array.
Example:
indexOf([1, 2, 1, 2], 2); // 1initial
Gets all but the last element of array.
Example:
initial([1, 2, 3]); // [1, 2]intersection
Creates an array of unique values that are included in all given arrays.
Example:
intersection([2, 1], [2, 3]); // [2]intersectionBy
This method is like intersection except that it accepts iteratee which is invoked for each element of each arrays to generate the criterion by which they're compared.
Example:
intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [2.1]intersectionWith
This method is like intersection except that it accepts comparator which is invoked to compare elements of arrays.
Example:
const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];join
Converts all elements in array into a string separated by separator.
Example:
join(['a', 'b', 'c'], '~'); // 'a~b~c'last
Gets the last element of array.
Example:
last([1, 2, 3]); // 3lastIndexOf
This method is like indexOf except that it iterates over elements of array from right to left.
Example:
lastIndexOf([1, 2, 1, 2], 2); // 3nth
Gets the element at index n of array. If n is negative, the nth element from the end is returned.
Example:
const array = ['a', 'b', 'c', 'd'];pull
Removes all given values from array.
Example:
const array = ['a', 'b', 'c', 'a', 'b', 'c'];pullAll
This method is like pull except that it accepts an array of values to remove.
Example:
const array = ['a', 'b', 'c', 'a', 'b', 'c'];pullAllBy
This method is like pullAll except that it accepts iteratee which is invoked for each element of array and values to generate the criterion by which they're compared.
Example:
const array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];pullAllWith
This method is like pullAll except that it accepts comparator which is invoked to compare elements of array to values.
Example:
const array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];pullAt
Removes elements from array corresponding to indexes and returns an array of removed elements.
Example:
const array = ['a', 'b', 'c', 'd'];remove
Removes all elements from array that predicate returns truthy for and returns an array of the removed elements.
Example:
const array = [1, 2, 3, 4];reverse
Reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.
Example:
const array = [1, 2, 3];slice
Creates a slice of array from start up to, but not including, end.
Example:
const array = [1, 2, 3, 4];sortedIndex
Uses a binary search to determine the lowest index at which value should be inserted into array in order to maintain its sort order.
Example:
sortedIndex([30, 50], 40); // 1sortedIndexBy
This method is like sortedIndex except that it accepts iteratee which is invoked for value and each element of array to compute their sort ranking.
Example:
const objects = [{ 'x': 4 }, { 'x': 5 }];sortedIndexOf
This method is like indexOf except that it performs a binary search on a sorted array.
Example:
sortedIndexOf([4, 5, 5, 5, 6], 5); // 1sortedLastIndex
This method is like sortedIndex except that it returns the highest index at which value should be inserted into array in order to maintain its sort order.
Example:
sortedLastIndex([4, 5, 5, 5, 6], 5); // 4sortedLastIndexBy
This method is like sortedLastIndex except that it accepts iteratee which is invoked for value and each element of array to compute their sort ranking.
Example:
const objects = [{ 'x': 4 }, { 'x': 5 }];sortedLastIndexOf
This method is like lastIndexOf except that it performs a binary search on a sorted array.
Example:
sortedLastIndexOf([4, 5, 5, 5, 6], 5); // 3sortedUniq
This method is like uniq except that it's designed and optimized for sorted arrays.
Example:
sortedUniq([1, 1, 2]); // [1, 2]sortedUniqBy
This method is like uniqBy except that it's designed and optimized for sorted arrays.
Example:
sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor); // [1.1, 2.3]tail
Gets all but the first element of array.
Example:
tail([1, 2, 3]); // [2, 3]take
Creates a slice of array with n elements taken from the beginning.
Example:
take([1, 2, 3]); // [1]takeRight
Creates a slice of array with n elements taken from the end.
Example:
takeRight([1, 2, 3]); // [3]takeRightWhile
Creates a slice of array with elements taken from the end. Elements are taken until predicate returns falsey.
Example:
const users = [takeWhile
Creates a slice of array with elements taken from the beginning. Elements are taken until predicate returns falsey.
Example:
const users = [union
Creates an array of unique values, in order, from all given arrays.
Example:
union([2], [1, 2]); // [2, 1]unionBy
This method is like union except that it accepts iteratee which is invoked for each element of each arrays to generate the criterion by which uniqueness is computed.
Example:
unionBy([2.1], [1.2, 2.3], Math.floor); // [2.1, 1.2]unionWith
This method is like union except that it accepts comparator which is invoked to compare elements of arrays.
Example:
const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];uniq
Creates a duplicate-free version of an array.
Example:
uniq([2, 1, 2]); // [2, 1]uniqBy
This method 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.
Example:
uniqBy([2.1, 1.2, 2.3], Math.floor); // [2.1, 1.2]uniqWith
This method is like uniq except that it accepts comparator which is invoked to compare elements of array.
Example:
const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];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.
Example:
const zipped = zip(['a', 'b'], [1, 2], [true, false]);unzipWith
This method is like unzip except that it accepts iteratee to specify how regrouped values should be combined.
Example:
const zipped = zip([1, 2], [10, 20], [100, 200]);without
Creates an array excluding all given values.
Example:
without([2, 1, 2, 3], 1, 2); // [3]xor
Creates an array of unique values that is the symmetric difference of the given arrays.
Example:
xor([2, 1], [2, 3]); // [1, 3]xorBy
This method is like xor except that it accepts iteratee which is invoked for each element of each arrays to generate the criterion by which they're compared.
Example:
xorBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [1.2, 3.4]xorWith
This method is like xor except that it accepts comparator which is invoked to compare elements of arrays.
Example:
const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];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.
Example:
zip(['a', 'b'], [1, 2], [true, false]); // [['a', 1, true], ['b', 2, false]]zipObject
This method is like fromPairs except that it accepts two arrays, one of property identifiers and one of corresponding values.
Example:
zipObject(['a', 'b'], [1, 2]); // { 'a': 1, 'b': 2 }zipObjectDeep
This method is like zipObject except that it supports property paths.
Example:
zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);zipWith
This method is like zip except that it accepts iteratee to specify how grouped values should be combined.
Example:
zipWith([1, 2], [10, 20], [100, 200], (a, b, c) => a + b + c);