@supercharge/arrays
Advanced tools
Changelog
2.0.0 - 2022-01-21
Arr
full classisArray
and isNotArray
methods detecting whether the given input is an arrayhas()
method: determine whether the array contains a given valueisMissing()
method: determine whether the array is missing a given valuemap()
method: returns a new array instance containing the results of applying a given transform function to each item in the arrayflatMap()
method: returns a new array instance containing the results of applying a given transform function to each item in the array and flatten the mapped results one level deepfrom
, isArray
, and isNotArray
methods to the Arr
classArr.from
does not accept a mapping function anymore
Arr.from(...items).map(…)
Arr.from(...items)
instead of Arr(...items)
// before
import { Arr } from '@supercharge/arrays'
const array = Arr([1, 2, 3])
// now
import { Arr } from '@supercharge/arrays'
const array = Arr.from([1, 2, 3])
Changelog
1.1.0 - 2022-01-10
at(index)
method: returns the item at the given index
or undefined
if the index exceeds the arrayfind(predicate)
: returns the first item in the array matching the given predicate
function, or undefined
if no such item was foundfindIndex(predicate)
: returns the index of the first element in the set where the given predicate
function is true
. Returns -1 otherwiselast(predicate?)
: returns the last array item when called without a predicate function. If you provide a predicate function this method is an alias for findLast
findLast(predicate)
: returns the last item in the set matching the given predicate function