Skip to content

Array Helpers

Utility functions for working with array operations.

Function Description
cartesianProduct Computes the Cartesian product of the provided arrays.
chunk Chunks an array into smaller arrays of specified size.
combineSortFns Chains multiple sort functions into a single comparator: the first function decides the order unless it reports a tie (…
compact Removes all falsy values (`false`, `null`, `undefined`, `0`, `“”`, `NaN`) from an array.
countBy Groups the elements of an array by the key returned by `keyFn` and returns a record mapping each key to the number of m…
createSortByBooleanFn Creates a sort function for objects by a boolean property.
createSortByDateFn Creates a sort function for objects by date property.
createSortByNaturalFn Creates a sort function for objects by one or more string properties using natural ordering.
createSortByNumberFn Creates a sort function for objects by number property.
createSortByStringFn Creates a sort function for objects by one or more string properties.
difference Returns the difference between two arrays (items in first array but not in second).
drop native JS Array.prototype.slice(n) (ES3)
ensureArray Wraps a value in an array if it is not already one.
equalsDeep Recursive structural array equality.
equalsShallow Positional, one-level (shallow) array equality.
equalsUnordered Order-independent (set-style) array equality.
filterAsync The async counterpart to `Array.prototype.filter`: runs `predicate` for every item and resolves to the items whose pred…
find / findIndex native JS Array.prototype.find() / findIndex() (ES2015)
flatten / flat native JS Array.prototype.flat(depth?) (ES2019)
forEachAsync The async counterpart to `Array.prototype.forEach`: runs `fn` for every item for its side effects, discarding any retur…
groupBy / group native JS Object.groupBy(arr, fn) (ES2024)
head / first native JS Array.prototype.at(0) (ES2022)
includes native JS Array.prototype.includes() (ES2016)
intersection Compute the intersection of two arrays, meaning the elements that are present in both arrays.
intersects Simple helper that check if two lists shared at least an item in common.
isEmpty Checks if an array is empty (has no elements).
isNonEmpty Checks if an array is non-empty (has at least one element).
last native JS Array.prototype.at(-1) (ES2022)
mapAsync The async counterpart to `Array.prototype.map`: applies `fn` to every item and resolves to an array of the results, in …
max Returns the maximum value in an array using a loop instead of spread, avoiding the call stack overflow that occurs with…
mean Calculates the arithmetic mean (average) of an array of numbers.
meanBy Calculates the arithmetic mean of numbers derived from each item of an array via an iteratee.
median Calculates the median (middle value) of an array of numbers.
min Returns the minimum value in an array using a loop instead of spread, avoiding the call stack overflow that occurs with…
partition Splits an array into two groups based on a predicate function.
percentile Calculates the p-th percentile of an array of numbers using linear interpolation between the closest ranks.
range Generates an array of sequential numbers from start to end (exclusive).
replaceOrAppend Returns a new array with the first item matching `predicate` replaced by `item` — or `item` appended at the end if no m…
reverse native JS Array.prototype.toReversed() (ES2023)
sample Picks one or more random elements from an array.
select Filters and transforms an array in a single pass.
select / filterMap native JS Array.prototype.filter().map() (ES5)
shuffle Randomly reorders elements of an array using the Fisher-Yates algorithm.
sort (immutable) native JS Array.prototype.toSorted(compareFn?) (ES2023)
sortBy / orderBy native JS Array.prototype.toSorted(fn?) (ES2023)
sortNumberAscFn Sort numbers in ascending order
sortNumberDescFn Sort numbers in descending order
sortStringAscFn Sort strings in ascending order
sortStringAscInsensitiveFn Sort strings in ascending order (case insensitive)
sortStringDescFn Sort strings in descending order
sortStringNaturalAscFn Sort strings in ascending order using natural (human-friendly) ordering.
sortStringNaturalAscInsensitiveFn Sort strings in ascending natural order, ignoring case **and diacritics** (`Intl.Collator { sensitivity: ‘base’ }` — tr…
sortStringNaturalDescFn Sort strings in descending order using natural (human-friendly) ordering.
sortStringNaturalDescInsensitiveFn Sort strings in descending natural order, ignoring case **and diacritics** (`Intl.Collator { sensitivity: ‘base’ }` — t…
sum Calculates the sum of an array of numbers.
sumBy Calculates the sum of numbers derived from each item of an array via an iteratee.
symmetricDifference Returns the symmetric difference between two arrays: items present in exactly one of the two arrays (in either, but not…
tail native JS Array.prototype.slice(1) (ES3)
take native JS Array.prototype.slice(0, n) (ES3)
toggle Returns a new array with `item` removed if present, or appended if absent — the common “toggle a selection” pattern.
union native JS unique([...a, ...b]) (ES2015)
unique Removes duplicate values from an array.
unzip Splits an array of tuples into separate arrays, one per position.
without Returns a new array with all occurrences of the given values removed.
zip Combines multiple arrays element-by-element into an array of tuples.