DEV Community

Discussion on: Object.entries() and Object.values() Methods in JavaScript

Collapse
 
bradtaniguchi profile image
Brad

I legit did not know you could do:

const map = new Map(Object.entries(birds));

I thought I was being sly for doing it manually with a single line reduce:

const map = Object.entries(birds).reduce(
  (map, [key, value]) => map.set(key, value),
  new Map()
);

Good to know! I will have to use the shorter version the next time I need an es6 map 😉