KeyOf
Returns the key of the first occurrence of a value in an object or null
Functional programming
- Typing:
(value: O[keyof O]) => keyof O | null
- Example:
import objectAsArray from "object-as-array";
export default function example() {
const obj = objectAsArray({
I : 1,
V : 5,
X : 10,
L : 50,
C : 100,
D : 500,
M : 1000
});
return obj.keyOf(100);
// Result: 'C'
}
Modular programming
- Typing:
<O extends object>(object: O, value: O[keyof O]) => keyof O | null
- Example:
import keyOf from "object-as-array/keyOf";
export default function example() {
const obj = {
I : 1,
V : 5,
X : 10,
L : 50,
C : 100,
D : 500,
M : 1000
};
return keyOf(obj, 100);
// Result: 'C'
}