Created
January 10, 2018 21:18
-
-
Save casesandberg/f743ea67a8f2df71a0a0914f711bbd33 to your computer and use it in GitHub Desktop.
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
// want to be able to ensure that the second param (key) exists as a key on the objects of the first type (array) | |
export const arrayToKeyedObj = (array: Array<{}>, key: string): {} => { | |
return array.reduce((acc, item) => { | |
acc[item[key]] = item | |
return acc | |
}, {}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment