VDL Plugin SDK

hasValue

Import from @varavel/vdl-plugin-sdk/utils/maps.

function hasValue<K, V>(map, searchElement): boolean;

Checks if a Map contains a specific value.

This function iterates through all values in the Map and checks if any value is equal to the search element using SameValueZero comparison (similar to Array.prototype.includes). This means that NaN is considered equal to NaN.

Type Parameters

Type ParameterDescription
KThe type of keys in the Map.
VThe type of values in the Map.

Parameters

ParameterTypeDescription
mapMap<K, V>The Map to search.
searchElementVThe value to search for.

Returns

boolean

true if the Map contains the value, false otherwise.

Example

const map = new Map([
  ['a', 1],
  ['b', 2],
  ['c', 3]
]);
const result = hasValue(map, 2);
// result will be: true

const result2 = hasValue(map, 5);
// result2 will be: false