Functions

Browse all available utility functions by category

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.

Example:

chunk(['a', 'b', 'c', 'd'], 2); // [['a', 'b'], ['c', 'd']]
arrays

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]
arrays

concat

Creates a new array concatenating array with any additional arrays and/or values.

Example:

const array = [1];
arrays

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]
arrays

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]
arrays

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 }];
arrays

drop

Creates a slice of array with n elements dropped from the beginning.

Example:

drop([1, 2, 3]); // [2, 3]
arrays

dropRight

Creates a slice of array with n elements dropped from the end.

Example:

dropRight([1, 2, 3]); // [1, 2]
arrays

dropRightWhile

Creates a slice of array excluding elements dropped from the end. Elements are dropped until predicate returns falsey.

Example:

const users = [
arrays

dropWhile

Creates a slice of array excluding elements dropped from the beginning. Elements are dropped until predicate returns falsey.

Example:

const users = [
arrays

fill

Fills elements of array with value from start up to, but not including, end.

Example:

const array = [1, 2, 3];
arrays

findIndex

Returns the index of the first element predicate returns truthy for instead of the element itself.

Example:

const users = [
arrays

findLastIndex

This method is like findIndex except that it iterates over elements of collection from right to left.

Example:

const users = [
arrays

first

Gets the first element of array.

Example:

first([1, 2, 3]); // 1
arrays

flatten

Flattens array a single level deep.

Example:

flatten([1, [2, [3, [4]], 5]]); // [1, 2, [3, [4]], 5]
arrays

flattenDeep

Recursively flattens array.

Example:

flattenDeep([1, [2, [3, [4]], 5]]); // [1, 2, 3, 4, 5]
arrays

flattenDepth

Recursively flatten array up to depth times.

Example:

const array = [1, [2, [3, [4]], 5]];
arrays

fromPairs

Returns an object composed from key-value pairs.

Example:

fromPairs([['a', 1], ['b', 2]]); // { 'a': 1, 'b': 2 }
arrays

head

Gets the first element of array.

Example:

head([1, 2, 3]); // 1
arrays

indexOf

Gets the index at which the first occurrence of value is found in array.

Example:

indexOf([1, 2, 1, 2], 2); // 1
arrays

initial

Gets all but the last element of array.

Example:

initial([1, 2, 3]); // [1, 2]
arrays

intersection

Creates an array of unique values that are included in all given arrays.

Example:

intersection([2, 1], [2, 3]); // [2]
arrays

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]
arrays

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 }];
arrays

join

Converts all elements in array into a string separated by separator.

Example:

join(['a', 'b', 'c'], '~'); // 'a~b~c'
arrays

last

Gets the last element of array.

Example:

last([1, 2, 3]); // 3
arrays

lastIndexOf

This method is like indexOf except that it iterates over elements of array from right to left.

Example:

lastIndexOf([1, 2, 1, 2], 2); // 3
arrays

nth

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'];
arrays

pull

Removes all given values from array.

Example:

const array = ['a', 'b', 'c', 'a', 'b', 'c'];
arrays

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'];
arrays

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 }];
arrays

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 }];
arrays

pullAt

Removes elements from array corresponding to indexes and returns an array of removed elements.

Example:

const array = ['a', 'b', 'c', 'd'];
arrays

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];
arrays

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];
arrays

slice

Creates a slice of array from start up to, but not including, end.

Example:

const array = [1, 2, 3, 4];
arrays

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); // 1
arrays

sortedIndexBy

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 }];
arrays

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); // 1
arrays

sortedLastIndex

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); // 4
arrays

sortedLastIndexBy

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 }];
arrays

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); // 3
arrays

sortedUniq

This method is like uniq except that it's designed and optimized for sorted arrays.

Example:

sortedUniq([1, 1, 2]); // [1, 2]
arrays

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]
arrays

tail

Gets all but the first element of array.

Example:

tail([1, 2, 3]); // [2, 3]
arrays

take

Creates a slice of array with n elements taken from the beginning.

Example:

take([1, 2, 3]); // [1]
arrays

takeRight

Creates a slice of array with n elements taken from the end.

Example:

takeRight([1, 2, 3]); // [3]
arrays

takeRightWhile

Creates a slice of array with elements taken from the end. Elements are taken until predicate returns falsey.

Example:

const users = [
arrays

takeWhile

Creates a slice of array with elements taken from the beginning. Elements are taken until predicate returns falsey.

Example:

const users = [
arrays

union

Creates an array of unique values, in order, from all given arrays.

Example:

union([2], [1, 2]); // [2, 1]
arrays

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]
arrays

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 }];
arrays

uniq

Creates a duplicate-free version of an array.

Example:

uniq([2, 1, 2]); // [2, 1]
arrays

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]
arrays

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 }];
arrays

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]);
arrays

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]);
arrays

without

Creates an array excluding all given values.

Example:

without([2, 1, 2, 3], 1, 2); // [3]
arrays

xor

Creates an array of unique values that is the symmetric difference of the given arrays.

Example:

xor([2, 1], [2, 3]); // [1, 3]
arrays

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]
arrays

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 }];
arrays

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]]
arrays

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 }
arrays

zipObjectDeep

This method is like zipObject except that it supports property paths.

Example:

zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
arrays

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