Created
September 10, 2020 03:55
-
-
Save lukethacoder/dec72895ccd538ec46732096c55bb7ba to your computer and use it in GitHub Desktop.
Inverse the Object keys/values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @description Inverse the Object keys/values | |
* @param {object} obj | |
*/ | |
export function inverseObjectKeysAndValues(obj: { [key: string]: any }) { | |
return Object.keys(obj).reduce( | |
(acc, curr) => ({ | |
...acc, | |
[obj[curr].toString()]: curr, | |
}), | |
{} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment