Category

Array

Utilities for working 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<T>(array: T[], size: number): T[][]

compact

Creates an array with all falsy values removed. The values false, null, 0, "", undefined, and NaN are falsy.

compact<T>(array: T[]): NonNullable<T>[]

flatten

Flattens array a single level deep.

flatten<T>(array: T[]): T[]

flattenDeep

Recursively flattens array to a single level.

flattenDeep<T>(array: T[]): any[]

uniq

Creates a duplicate-free version of an array, using SameValueZero for equality comparisons.

uniq<T>(array: T[]): T[]

uniqBy

Creates a duplicate-free version of an array using a comparator function to determine uniqueness.

uniqBy<T, U>(array: T[], iteratee: (value: T) => U): T[]

fill

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

fill<T>(array: any[], value: T, start?: number, end?: number): any[]

findIndex

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

findIndex<T>(array: T[], predicate: (value: T) => boolean, fromIndex?: number): number

findLastIndex

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

findLastIndex<T>(array: T[], predicate: (value: T) => boolean, fromIndex?: number): number

first

Gets the first element of array. Alias for head.

first<T>(array: T[]): T | undefined

flattenDepth

Recursively flatten array up to depth times.

flattenDepth<T>(array: any[], depth?: number): any[]

fromPairs

The inverse of toPairs; this method returns an object composed from key-value pairs.

fromPairs<T>(pairs: [string | number | symbol, T][]): Record<string | number | symbol, T>

head

Gets the first element of array.

head<T>(array: T[]): T | undefined

indexOf

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

indexOf<T>(array: T[], value: T, fromIndex?: number): number

join

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

join(array: any[], separator?: string): string

last

Gets the last element of array.

last<T>(array: T[]): T | undefined

lastIndexOf

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

lastIndexOf<T>(array: T[], value: T, fromIndex?: number): number

nth

Gets the element at index n of array. If n is negative, the nth element from the end is returned.

nth<T>(array: T[], n: number): T | undefined

pull

Removes all given values from array using SameValueZero for equality comparisons.

pull<T>(array: T[], ...values: T[]): T[]

pullAll

This method is like pull except that it accepts an array of values to remove.

pullAll<T>(array: T[], values: T[]): T[]

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.

pullAllBy<T, U>(array: T[], values: T[], iteratee: (value: T) => U): T[]

pullAllWith

This method is like pullAll except that it accepts comparator which is invoked to compare elements of array to values.

pullAllWith<T>(array: T[], values: T[], comparator: (a: T, b: T) => boolean): T[]

pullAt

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

pullAt<T>(array: T[], indexes: number[]): T[]

remove

Removes all elements from array that predicate returns truthy for and returns an array of the removed elements.

remove<T>(array: T[], predicate: (value: T, index: number, array: T[]) => boolean): T[]

reverse

Reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.

reverse<T>(array: T[]): T[]

slice

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

slice<T>(array: T[], start?: number, end?: number): T[]

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.

sortedIndex<T>(array: T[], value: T): number

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.

sortedIndexBy<T, U>(array: T[], value: T, iteratee: (value: T) => U): number

sortedIndexOf

This method is like indexOf except that it performs a binary search on a sorted array.

sortedIndexOf<T>(array: T[], value: T): number

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.

sortedLastIndex<T>(array: T[], value: T): number

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.

sortedLastIndexBy<T, U>(array: T[], value: T, iteratee: (value: T) => U): number

sortedLastIndexOf

This method is like lastIndexOf except that it performs a binary search on a sorted array.

sortedLastIndexOf<T>(array: T[], value: T): number

sortedUniq

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

sortedUniq<T>(array: T[]): T[]

sortedUniqBy

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

sortedUniqBy<T, U>(array: T[], iteratee: (value: T) => U): U[]

tail

Gets all but the first element of array.

tail<T>(array: T[]): T[]

take

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

take<T>(array: T[], n?: number): T[]

takeRight

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

takeRight<T>(array: T[], n?: number): T[]

takeRightWhile

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

takeRightWhile<T>(array: T[], predicate: (value: T) => boolean): T[]

takeWhile

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

takeWhile<T>(array: T[], predicate: (value: T) => boolean): T[]