Skip to content

Instantly share code, notes, and snippets.

@lukethacoder
Created September 10, 2020 03:55
Show Gist options
  • Save lukethacoder/dec72895ccd538ec46732096c55bb7ba to your computer and use it in GitHub Desktop.
Save lukethacoder/dec72895ccd538ec46732096c55bb7ba to your computer and use it in GitHub Desktop.
Inverse the Object keys/values
/**
* @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