@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
17 lines (15 loc) • 492 B
JavaScript
/**
* Given an object and a value, find the first property with matching value and returns name of that property
* Useful for working with ENUM-like objects
* @param {Object<T>} object
* @param {T} value
* @returns {string|undefined} name of the property, or undefined if property not found
*/
export function objectKeyByValue(object, value) {
for (let i in object) {
if (object[i] === value) {
return i;
}
}
return undefined;
}