Created
September 24, 2019 07:10
-
-
Save ricardodantas/941342fc1753349c165724c55a7e32e2 to your computer and use it in GitHub Desktop.
Converting an Array of Objects to an Object
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
const arrayToObject = (array, keyField) => | |
array.reduce((obj, item) => { | |
return {...obj, [item[keyField]]: item} | |
}, {}); | |
const peopleObject = arrayToObject(peopleArray, "id"); | |
console.log(peopleObject); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment