Skip to content

Instantly share code, notes, and snippets.

@examinedliving
Last active July 13, 2020 21:48
Show Gist options
  • Save examinedliving/41dbc7b8dafeacbc659adaf83eae40e7 to your computer and use it in GitHub Desktop.
Save examinedliving/41dbc7b8dafeacbc659adaf83eae40e7 to your computer and use it in GitHub Desktop.
Converts array of Objects to Object of Objects with optional key name
function arrayToObject(array, key) {
var initialValue = {};
var _key = {};
return array.reduce((obj, item) => {
return {
...obj,
[item[key]]: item,
};
}, initialValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment