Created
September 28, 2021 19:05
-
-
Save SparK-Cruz/a05d1fe1e4a1ece8b6b9eb81f6ad1f35 to your computer and use it in GitHub Desktop.
Array monkey-patch to flip keys and values into an object
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
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