Use ES6 Maps with a bunch of convenience methods. Help improve the ES6 spec!
var map = 'foo' 'bar';map;// Filter map by a functionmap;0 42// Merge Mapsmap;0 42 'baz' 'thing'// map.get with a defaultmap;'default'// Invert map (makes keys->values and vice versa)map;42 0 'thing' 'baz'// Destructive filter (inline map delete)map;map;false// Remove all itemsmapclear;// Check if Map has no itemsmap;true
In browsers, include smap-shim.js in your page:
You can install this via:
npm install smap
component install eriwen/smap.js
bower install smap
If you also use the es5-shim, you can use this in:
Boris Smus makes an excellent suggestion for moving the web forward: forward polyfills. I hope this project can be the basis for a future proposal to TC39. Please gratuitously discuss Map and WeakMap workings in issues, and add methods/tests with pull requests.