Created
November 19, 2019 09:27
-
-
Save ChrisWhealy/a4fb8620b84915ed4cbae0f9eb9a8305 to your computer and use it in GitHub Desktop.
Turn an array into an object based on an array element's property name
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.makeObjectOn = function(prop) { | |
return this.reduce((acc, el, idx) => { | |
acc[el[prop] || idx] = el | |
return acc | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment