findMap
Returns the first non-undefined result of mapping fn over array, short-circuiting as
soon as one is found. Similar to array.map(fn).find(v => v !== undefined), but doesn’t map
(or call fn on) the remaining items once a match is found.
null and undefined are treated as empty arrays and return undefined.
Available since v3.1.1
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
array | readonly T[] | null | undefined | The array to search |
fn | function | Maps each item (and its index) to a result, or `undefined` to keep looking |
Returns
Section titled “Returns”R | undefined — The first non-undefined result of fn, or undefined if none was found
Examples
Section titled “Examples”Find the first transformed match
Section titled “Find the first transformed match”Returns the mapped value, not the original item — stops as soon as one is found.
Try several fallible lookups in priority order
Section titled “Try several fallible lookups in priority order”Chain several ?? -style lookups per item and stop at the first one that succeeds anywhere in the array.
