DEV Community

loading...

Discussion on: How to convert an array into an object in javascript

Collapse
artezan profile image
artezan • Edited

I faced out with this problem and I took as a reference: stackoverflow.com/a/44325124

And I created some similar that your solution but with less lines and more faster

const convertArrayToObject = (array, key) => 
   array.reduce((obj, item) => ((obj[[item[key]]] = item), obj), {});



Collapse
afewminutesofcode profile image
Aaron Author

Thanks for the reference their artezan, the explanations in those answers have really helped my understanding!