DEV Community


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

artezan profile image
artezan • Edited

I faced out with this problem and I took as a reference:

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), {});

afewminutesofcode profile image
Aaron Author

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