Skip to content

Instantly share code, notes, and snippets.

@NuroDev
Created September 29, 2022 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NuroDev/62956708852a6679779114904d201eaf to your computer and use it in GitHub Desktop.
Save NuroDev/62956708852a6679779114904d201eaf to your computer and use it in GitHub Desktop.
πŸ”ƒ Flip Entries ─ Take the elements of an object & swap the keys with values
function flipEntries <TValue = unknown> (obj: Record<string, TValue>) {
return Object.fromEntries(Object.entries(obj).map(([key, value]) => Array.isArray(value) ? [...value.map((v) => [v, key])] : [[value, key]]).flat())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment