There are two possible constructors:
new go.Map()
, for JavaScript
new go.Map<K, V>()
for TypeScript
In TypeScript, the two optional generic arguments describe the types of keys and the types of values that this Map may hold.
For example, the expression:
// TypeScript:
new go.Map<string, go.Point>()
produces a Map that has keys that must be strings and whose associated values must be Points.
Read-only
count
This read-only property is the number of associations in the Map.
Read-only
iterator
Gets an object that you can use for iterating over the key-value pairs of a Map. Typical usage:
var it = aMap.iterator;
while (it.next()) {
console.log("the key: " + it.key + " has value: " + it.value);
}
Read-only
iteratorGets an object that you can use for iterating over the keys of a Map. Typical usage:
var it = aMap.iteratorKeys;
while (it.next()) {
console.log("key: " + it.value);
}
Read-only
iteratorGets an object that you can use for iterating over the values of a Map. Typical usage:
var it = aMap.iteratorValues;
while (it.next()) {
console.log("value: " + it.value);
}
Read-only
size
This read-only property is the number of associations in the Map.
Adds a key-value association to the Map, or replaces the value associated with the key if the key was already present in the map.
Be careful not to call this method while iterating over the collection.
The key or index for storing the value in the Map.
The value to add to the Map, associated with the key.
This modified Map.
Adds all of the key-value pairs of another Map to this Map. If a key is already present in this Map, its value is replaced with the corresponding value from the given map.
Be careful not to call this method while iterating over the collection.
This modified Map.
Virtual
allThis is true if all invocations of the given predicate on items in the collection are true.
Call the given predicate on each key/value pair in the collection. As soon as a call returns false, this returns false. Otherwise this returns true. For an empty collection this returns true.
The argument to the predicate will be an object with both "key" and "value" properties. This function must not have any side-effects.
True if all predicate calls are true; false otherwise.
Virtual
anyThis is true if any invocation of the given predicate on items in the collection is true.
Call the given predicate on each key/value pair in the collection. As soon as a call returns true, this returns true. Otherwise this returns false. For an empty collection this returns false.
The argument to the predicate will be an object with both "key" and "value" properties. This function must not have any side-effects.
True if any predicate call is true; false otherwise.
Clears the Map, removing all key-value associations. This sets the count to zero.
Be careful not to call this method while iterating over the collection.
Virtual
copyVirtual
eachCall the given function on each key/value pair in the collection.
The argument to the function will be an object with both "key" and "value" properties. This function must not modify the collection.
This Map itself
Adds a key-value association to the Map, or replaces the value associated with the key if the key was already present in the map.
Be careful not to call this method while iterating over the collection.
The key or index for storing the value in the Map.
The value to add to the Map, associated with the key.
This modified Map.
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:
You can iterate over the key/value pairs in a Map:
Or:
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:
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.
template
V