Skip to content

Instantly share code, notes, and snippets.

@SparK-Cruz
Created September 28, 2021 19:05
Show Gist options
  • Save SparK-Cruz/a05d1fe1e4a1ece8b6b9eb81f6ad1f35 to your computer and use it in GitHub Desktop.
Save SparK-Cruz/a05d1fe1e4a1ece8b6b9eb81f6ad1f35 to your computer and use it in GitHub Desktop.
Array monkey-patch to flip keys and values into an object
Array.prototype.flip = function() {
const obj = {};
this.forEach((e, i) => {
obj[e] = i;
});
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment