Mapsubclass with support for multiple keys for one entry.
ManyKeysMap object is identical to a regular
Map, which the exception that it only supports a sequence of keys as key, instead of a single key. This will let you attach a value to a specific combination of keys, instead of a single key.
const regularMap = ;regularMap;const manyKeysMap = ;manyKeysMap;
This is useful when the keys cannot be easily combined (i.e. object)
const handlers = ;handlers;handlers;// Since objects are stored by reference, it’s best to stringify `options` object like the abovehandlers;
The number of keys allowed is unlimited and their order matters.
$ npm install many-keys-map
It should work exactly the same as a
Map, except that the
key must always be an array.
const ManyKeysMap = ;const groups = ;groups;groups;const data ='hello key' 'value'42 null;data;// => 'value'data;// => date Objectdata;// => undefineddata;// => falsefor const keys value of dataconsole;console;// => ['hello key']// => 'value'// => [42, null]// => date Object
- Keys must always be an array, e.g.
.set([a, b], 'hello')
- Only the values in the
keysarray are stored, not the array itself — so future changes to the array won’t be reflected in the map.
ManyKeysMapsupports any number of keys, any of these are valid and different:
.get([a, b, c, d, e, f, g])
- The order of keys matters, so
.get([a, b])is different from
- The keys can be anything supported by
- many-keys-weakmap - A
WeakMapsubclass with support for multiple keys for one entry.