Array Helpers
Utility functions for working with array operations.
Functions
Section titled “Functions”| Function | Description |
|---|---|
chunk | Chunks an array into smaller arrays of specified size |
compact | Removes all falsy values (false, null, undefined, 0, "", NaN) from an array. |
createSortByDateFn | Creates a sort function for objects by date property |
createSortByNumberFn | Creates a sort function for objects by number property |
createSortByStringFn | Creates a sort function for objects by string property |
deepEquals | Deep comparison of two arrays that only returns true or false. |
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. |
equals | Simple helper that checks if two lists are identical. |
find / findIndex | native JS Array.prototype.find() / findIndex() (ES2015) |
flatten / flat | native JS Array.prototype.flat(depth?) (ES2019) |
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. |
last | native JS Array.prototype.at(-1) (ES2022) |
oneInCommon | Simple helper that check if two lists shared at least an item in common. |
partition | Splits an array into two groups based on a predicate function. |
range | Generates an array of sequential numbers from start to end (exclusive). |
reverse | native JS Array.prototype.toReversed() (ES2023) |
sample | Picks one or more random elements from an array. |
shallowEquals | Quick comparison of two arrays using JSON.stringify. |
shuffle | Randomly reorders elements of an array using the Fisher-Yates algorithm. |
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 |
tail | native JS Array.prototype.slice(1) (ES3) |
take | native JS Array.prototype.slice(0, n) (ES3) |
unique | Removes duplicate values from an array |