Skip to content

getKeyObjectFromValue

Function that given an object and a value, returns the corrispondent key of this value or undefined.

Types

GetKeyObjectFromValueProps

  • @template T - The object type to search within.
  • @template E - The type of the key to return. Defaults to keyof T.

Parameters accepted by getKeyObjectFromValue.

PropertyTypeRequiredDescription
objectTThe object to search through. Its values are compared against value using strict equality.
valueunknownThe value to look up within object. When a property of object strictly equals this value, the corresponding key is returned. When omitted or when no match is found, undefined is returned.

GetKeyObjectFromValueResult

  • @template E - The key type, defaulting to keyof T.

Return value of getKeyObjectFromValue.

The key of type E whose associated value in the object strictly equals the searched value, or undefined when no match is found.

ts
export type GetKeyObjectFromValueResult<E extends string | number | symbol> = E | undefined;

Released under the MIT License.