Skip to content

findValue

Returns the first value of a Map whose entry satisfies the predicate, in insertion order.

Available since v3.0.3

import { findValue } from '@helpers4/map';
// or, from the all-in-one package (same code, one install):
import { findValue } from 'helpers4/map';
findValue<K, V>(map: ReadonlyMap<K, V>, predicate: function): V | undefined
ParameterTypeDescription
mapReadonlyMap<K, V>The Map to search
predicatefunctionFunction invoked with (value, key)

V | undefined — The matching value, or undefined if none matches

Searches in insertion order and returns the value of the first match.

findValue(new Map([['a', 1], ['b', 2]]), value => value > 1)
// => 2

Returns undefined when nothing satisfies the predicate.

findValue(new Map([['a', 1]]), value => value > 10)
// => undefined

View source on GitHub