Functions
Browse all available utility functions by category
countBy
Creates an object composed of keys generated from the results of running each element of collection thru iteratee. The corresponding value of each key is the number of times the key was returned by iteratee.
Example:
countBy([6.1, 4.2, 6.3], Math.floor); // { '4': 1, '6': 2 }each
Iterates over elements of collection and invokes iteratee for each element. The iteratee is invoked with three arguments: (value, index|key, collection).
Example:
each([1, 2], (value) => console.log(value)); // Logs `1` then `2`eachRight
This method is like each except that it iterates over elements of collection from right to left.
Example:
eachRight([1, 2], (value) => console.log(value)); // Logs `2` then `1`every
Checks if predicate returns truthy for all elements of collection.
Example:
every([true, 1, null, 'yes'], Boolean); // falsefilter
Iterates over elements of collection, returning an array of all elements predicate returns truthy for.
Example:
const users = [find
Iterates over elements of collection, returning the first element predicate returns truthy for.
Example:
const users = [findLast
This method is like find except that it iterates over elements of collection from right to left.
Example:
findLast([1, 2, 3, 4], (n) => n % 2 === 1); // 3flatMap
Creates a flattened array of values by running each element in collection thru iteratee and flattening the mapped results.
Example:
function duplicate(n: number) {flatMapDeep
This method is like flatMap except that it recursively flattens the mapped results.
Example:
function duplicate(n: number) {flatMapDepth
This method is like flatMap except that it recursively flattens the mapped results up to depth times.
Example:
function duplicate(n: number) {forEach
Iterates over elements of collection and invokes iteratee for each element.
Example:
forEach([1, 2], (value) => console.log(value)); // Logs `1` then `2`forEachRight
This method is like forEach except that it iterates over elements of collection from right to left.
Example:
forEachRight([1, 2], (value) => console.log(value)); // Logs `2` then `1`groupBy
Creates an object composed of keys generated from the results of running each element of collection thru iteratee. The order of grouped values is determined by the order they occur in collection.
Example:
groupBy([6.1, 4.2, 6.3], Math.floor); // { '4': [4.2], '6': [6.1, 6.3] }includes
Checks if value is in collection.
Example:
includes([1, 2, 3], 1); // trueinvokeMap
Invokes the method at path of each element in collection, returning an array of the results of each invoked method.
Example:
invokeMap([[5, 1, 7], [3, 2, 1]], 'sort'); // [[1, 5, 7], [1, 2, 3]]keyBy
Creates an object composed of keys generated from the results of running each element of collection thru iteratee. The corresponding value of each key is the last element responsible for generating the key.
Example:
const array = [map
Creates an array of values by running each element in collection thru iteratee.
Example:
function square(n: number) {orderBy
This method is like sortBy except that it allows specifying the sort orders of the iteratees to sort by.
Example:
const users = [partition
Creates an array of elements split into two groups, the first of which contains elements predicate returns truthy for, the second of which contains elements predicate returns falsey for.
Example:
const users = [reduce
Reduces collection to a value which is the accumulated result of running each element in collection thru iteratee.
Example:
reduce([1, 2], (sum, n) => sum + n, 0); // 3reduceRight
This method is like reduce except that it iterates over elements of collection from right to left.
Example:
const array = [[0, 1], [2, 3], [4, 5]];reject
The opposite of filter; this method returns the elements of collection that predicate does not return truthy for.
Example:
const users = [sample
Gets a random element from collection.
Example:
sample([1, 2, 3, 4]); // 2 (random)sampleSize
Gets n random elements at unique keys from collection up to the size of collection.
Example:
sampleSize([1, 2, 3], 2); // [3, 1] (random)shuffle
Creates an array of shuffled values, using a version of the Fisher-Yates shuffle.
Example:
shuffle([1, 2, 3, 4]); // [4, 1, 3, 2] (random)size
Gets the size of collection by returning its length for array-like values or the number of own enumerable string keyed properties for objects.
Example:
size([1, 2, 3]); // 3some
Checks if predicate returns truthy for any element of collection.
Example:
some([null, 0, 'yes', false], Boolean); // truesortBy
Creates an array of elements, sorted in ascending order by the results of running each element in a collection thru each iteratee.
Example:
const users = [