Last active
July 13, 2020 21:48
-
-
Save examinedliving/41dbc7b8dafeacbc659adaf83eae40e7 to your computer and use it in GitHub Desktop.
Converts array of Objects to Object of Objects with optional key name
This file contains hidden or 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
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