Skip to content

Array Helpers

Utility functions for working with array operations.

FunctionDescription
chunkChunks an array into smaller arrays of specified size
compactRemoves all falsy values (false, null, undefined, 0, "", NaN) from an array.
createSortByDateFnCreates a sort function for objects by date property
createSortByNumberFnCreates a sort function for objects by number property
createSortByStringFnCreates a sort function for objects by string property
deepEqualsDeep comparison of two arrays that only returns true or false.
differenceReturns the difference between two arrays (items in first array but not in second)
dropnative JS Array.prototype.slice(n) (ES3)
ensureArrayWraps a value in an array if it is not already one.
equalsSimple helper that checks if two lists are identical.
find / findIndexnative JS Array.prototype.find() / findIndex() (ES2015)
flatten / flatnative JS Array.prototype.flat(depth?) (ES2019)
groupBy / groupnative JS Object.groupBy(arr, fn) (ES2024)
head / firstnative JS Array.prototype.at(0) (ES2022)
includesnative JS Array.prototype.includes() (ES2016)
intersectionCompute the intersection of two arrays, meaning the elements that are present in both arrays.
lastnative JS Array.prototype.at(-1) (ES2022)
oneInCommonSimple helper that check if two lists shared at least an item in common.
partitionSplits an array into two groups based on a predicate function.
rangeGenerates an array of sequential numbers from start to end (exclusive).
reversenative JS Array.prototype.toReversed() (ES2023)
samplePicks one or more random elements from an array.
shallowEqualsQuick comparison of two arrays using JSON.stringify.
shuffleRandomly reorders elements of an array using the Fisher-Yates algorithm.
sortBy / orderBynative JS Array.prototype.toSorted(fn?) (ES2023)
sortNumberAscFnSort numbers in ascending order
sortNumberDescFnSort numbers in descending order
sortStringAscFnSort strings in ascending order
sortStringAscInsensitiveFnSort strings in ascending order (case insensitive)
sortStringDescFnSort strings in descending order
tailnative JS Array.prototype.slice(1) (ES3)
takenative JS Array.prototype.slice(0, n) (ES3)
uniqueRemoves duplicate values from an array