Skip to content

Instantly share code, notes, and snippets.

@ChrisWhealy
Created November 19, 2019 09:27
Show Gist options
  • Save ChrisWhealy/a4fb8620b84915ed4cbae0f9eb9a8305 to your computer and use it in GitHub Desktop.
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
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