HexagonJS
Edit Page
Map
A map collection type. Proper maps are coming in ECMAScript 6 (which at time of writing has a scheduled release date of June 2015). This map object tries to keep as close as possible to the currently planned spec for maps, which should make it easier to swap out for the native implementation when it arrives and is well supported enough in browsers.
Examples
// create an empty map
var map = new hx.Map;

map.set('a', 1);
map.set('b', 2);
map.set('c', 3);

// will log 3
console.log(map.size);

// remove an item from the map by key
map.delete('a');

// will log [2, 3]
console.log(map.values());

// will log [['b', 2], ['c', 3]]
console.log(map.entries());

// will log ['b', 'c']
console.log(map.keys());

// removes everything from the map
map.clear();

// create a map prefilled with some values
map = new hx.Map([['a', 1], ['b', 1], ['c', 2], ['d', 3], ['e', 3], ['f', 3]]);

// will log true
console.log(map.has('d'));

// will log false
console.log(map.has('g'));

// will log 3
console.log(map.get('f'));

// this will log each key and value in the map
map.forEach(function(k, v) {
  console.log(k + ': ' + v)
});
Api
Prototypes
hx.Mapdeprecated
Deprecated
Deprecated in favour of native ES6 Map
A map collection type.
Constructors
hx.MaparrayArray
Arguments
arrayArray
An array of 2-element arrays containing the values to initialise the map with
Properties
sizeNumber
The current size of the map
Methods
clearMap
Removes all entries from the Map, resulting in an empty map with size 0. Returns this Map for chaining.
Returns
Map
deletekeyStringMap
Removes an entry from the map by key.
Arguments
The key to remove
Returns
Map
entriesArray
Returns the items in the map as an array of 2-element arrays. The first entry in each of these arrays is the key, the second entry is the value.
Returns
forEachfFunctionthisArgObjectMap
Calls the function supplied for each entry in the map. Returns this map for chaining.
Arguments
fkeyStringvalueObject
The function that should be called for each entry. First parameter is the key, second is the value.
Arguments
The key the entry was stored under
value
The value stored against the key
thisArg
A parameter which lets you supply the 'this' context to be used when calling f. The default is to use this Map.
Returns
Map
Gets an item by key. Returns undefined if there is no entry for the key supplied.
Arguments
The key to use.
Returns
Object
Checks if the map contains a key. Returns true if the value is in the map, false otherwise.
Arguments
The key to use
Returns
keysArray
Returns an array of the keys in this Map.
Returns
setkeyStringvalueAnyMap
Stores the value for the given key. Returns this Map for chaining.
Arguments
The key to use.
valueAny
The value to store.
Returns
Map
valuesArray
Returns an array of the values in this Map.
Returns