Skip to content

hasValue

Checks whether a value exists anywhere in a Map (Map.prototype.has checks keys, not values). Uses Object.is-style equality (via ===, with NaN matching NaN).

Available since v3.0.3

import { hasValue } from '@helpers4/map';
// or, from the all-in-one package (same code, one install):
import { hasValue } from 'helpers4/map';
hasValue<K, V>(map: ReadonlyMap<K, V>, value: V): boolean
ParameterTypeDescription
mapReadonlyMap<K, V>The Map to search
valueVThe value to look for

boolean — true if the value is found in at least one entry

Unlike Map.prototype.has (which checks keys), this checks values.

hasValue(new Map([['a', 1], ['b', 2]]), 2)
// => true

Returns false when no entry has that value.

hasValue(new Map([['a', 1]]), 99)
// => false

View source on GitHub