Map<K, V> class

NOTE: For 2.0 the #constructor arguments have changed. Map now optionally accepts a collection, and only checks types in TypeScript.

An unordered iterable collection of key/value pairs that cannot contain two instances of the same key. In TypeScript it is a generic class that enforces at compile-time the type of the key and the type of the associated value.

To create a Map:

  var map = new go.Map(); // In TypeScript: new go.Map<string, number>();
  map.add("one", 1);
  map.add("two", 2);
  map.add("three", 3);
  // now map.count === 3
  // and map.getValue("two") === 2
  // and map.contains("zero") === false

You can iterate over the key/value pairs in a Map:

  var it = aMap.iterator;
  while (it.next()) {
    console.log(it.key + ": " + it.value);
  }

Or:

  aMap.each(kvp => {
    console.log(kvp.key + ": " + kvp.value);
  });

But note that there is no guaranteed ordering amongst the key/value pairs.

Call #toKeySet to get a read-only Set that holds all of the keys of a Map. Iterating over that Set will produce values that are the keys in the Map.

Although not precisely implementing the features and semantics of the EcmaScript 6 Map class, this GoJS Map class has synonyms for the following methods and property:

  • get(key): #getValue, but returns null instead of undefined when key is not present
  • set(key,val): #add
  • has(key): #contains
  • delete(key): #remove
  • clear(): #clear
  • size: #count

The constructor now takes an optional Iterable or Array argument that provides the initial entries for the new Map.

Note that GoJS iteration is quite different than ES6 iteration, so that functionality has not been made somewhat compatible. These collection classes were defined in GoJS before the ES6 collection classes were proposed.

Available Extensions
Annotations
  • @JS()
  • @staticInterop

Constructors

Map([Object? coll])
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited