DEV Community

loading...

Discussion on: JavaScript: Map an array of objects to a dictionary

Collapse
lukaszahradnik profile image
Lukáš Zahradník

The same thing using reduce

let dictionary = data.reduce((a,x) => ({...a, [x.id]: x.country}), {})
Enter fullscreen mode Exit fullscreen mode