Function getMapKeyByValue

  • Finds the first key in a Map that corresponds to the specified value.

    Returns

    The first key whose value strictly equals (===) the searchValue, or undefined if no match is found.

    Example

    const myMap = new Map<string, number>([['a', 1], ['b', 2], ['c', 1]]);
    getMapKeyByValue(myMap, 1); // → 'a'
    getMapKeyByValue(myMap, 3); // → undefined

    Remarks

    • Only the first matching key is returned; subsequent keys with the same value are ignored.
    • Comparison uses strict equality (===).

    Type Parameters

    • K

      The type of keys in the map.

    • V

      The type of values in the map.

    Parameters

    • map: Map<K, V>

      The map to search.

    • searchValue: V

      The value to find the corresponding key for.

    Returns K | undefined

Generated using TypeDoc