@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
22 lines (18 loc) • 595 B
JavaScript
import { assert } from "../../assert.js";
/**
* 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
* @template T
* @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) {
assert.isObject(object, 'object');
for (let i in object) {
if (object[i] === value) {
return i;
}
}
return undefined;
}