API Reference > bentleyjs-core > Collections > Dictionary Dictionary<K, V> Class Maintains a mapping of keys to values. Unlike the standard Map<K, V>, a Dictionary<K, V> supports custom comparison logic for keys of object type (and for any other type). The user supplies a key comparison function to the constructor, that must meet the following criteria given 'lhs' and 'rhs' of type K: If lhs is equal to rhs, returns 0 If lhs is less than rhs, returns a negative value If lhs is greater than rhs, returns a positive value If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0 If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa. Modifying a key in a way that affects the comparison function will produce unpredictable results, the most likely of which is that keys will cease to map to the values with which they were initially inserted. Implements Iterable<DictionaryEntry<K, V>> Methods Name Description constructor(compareKeys: OrderedComparator<K>, cloneKey: CloneFunction<K> = shallowClone, cloneValue: CloneFunction<V> = shallowClone): Dictionary Construct a new Dictionary<K, V>. [Symbol.iterator](): Iterator<DictionaryEntry<K, V>> Returns an iterator over the key-value pairs in the Dictionary suitable for use in for-of loops. clear(): void Removes all entries from this dictionary delete(key: K): boolean Deletes a value using its key. extractArrays(): { keys: K[], values: V[] } Extracts the contents of this dictionary as a pair of { keys, values } arrays, and empties this dictionary. extractPairs(): Array<{ key: K, value: V }> Extracts the contents of this dictionary as an array of { key, value } pairs, and empties this dictionary. forEach(func: (key: K, value: V) => void): void Apply a function to each (key, value) pair in the dictionary, in sorted order. get(key: K): V | undefined Looks up a value by its key. has(key: K): boolean Determines if an entry exists for the specified key insert(key: K, value: V): boolean Attempts to insert a new entry into the dictionary. lowerBound(key: K): { equal: boolean, index: number } Protected Computes the position at which the specified key should be inserted to maintain sorted order. set(key: K, value: V): void Sets the value associated with the specified key in the dictionary. Properties Name Type Description _cloneKey Protected CloneFunction<K> _cloneValue Protected CloneFunction<V> _compareKeys Protected OrderedComparator<K> _keys Protected K[] _values Protected V[] size Accessor ReadOnly number The number of entries in the dictionary. Defined in core/bentley/src/Dictionary.ts Line 60 Last Updated: 13 June, 2024