Objectmap
mapobject
Use a ES6 map, like an object.
This module is one of those rare hidden gems in npm, it's already a year old, it makes uses of ES6 reflect API with proxy to make give us a convience method so that maps can be used like an Object.
What other advantages apart from syntax sugar?
Iterate it like a regular object with
(for in)
without worrying abouthasOwnProperty
checks.Iterate it
(for of)
you will get arrays of length 2 of both keys and values.
Install it: npm install --save objectmap
Sample usage:
1 2 3 4 5 6 7 8 9 |
|
Caveat: map[3]
implies map.set('3')
not map.set(3)
GIF FTW!
Thanks to Calvin for this useful util :)