DEV Community

Maps in ES6 - A Quick Guide

Ben Mildren on December 11, 2017

Overview Maps and Sets often get lumped together in articles. They're both new ES6 collection types with similar interfaces but that's where the...
Collapse
 
joegaudet profile image
Joe Gaudet

Minor gripe, but why oh why is the interface of for each (value, key) and not (key,value) seems backwards.

Also that #entries doesn't expose normal higher order functions is a bit lame.

Collapse
 
mildrenben profile image
Ben Mildren

I agree, would've been nice with key, value. But forEach on arrays is val, key - so I can see why they did it that way.

I don't fully understand what you mean about entries though?

Collapse
 
joegaudet profile image
Joe Gaudet
const map = new Map();
map.set('foo', 'bar');

// none of these are defined as entries is an
// iterator not a list
map.entries.map
map.entries.forEach
map.entries.filter
Collapse
 
joegaudet profile image
Joe Gaudet

See it's weird that arrays are forEach((val, index)), and Object.entries(object).forEach(([key, value])... Just seems inconsistent.