Skip to content

TwoWayMap<Key, Value>

A map that allows you to look up a value by its key and vice versa.

Import:

import { TwoWayMap } from 'obsidian-dev-utils/two-way-map';

Example:

const map = new TwoWayMap<string, number>();
map.set('foo', 42);
map.getValue('foo'); // 42
map.getKey(42); // 'foo'
map.deleteKey('foo');
map.deleteValue(42);
map.clear();

Signature:

export class TwoWayMap<Key, Value>

Constructor

new TwoWayMap(entries?: (readonly [key: Key, value: Value])[])

Creates a new two-way map.

Methods

MethodReturnsDescription
clear()voidClears the map.
deleteKey(key)voidDeletes a key from the map.
deleteValue(value)voidDeletes a value from the map.
entries()IterableIterator<readonly [key: Key, value: Value]>Gets all entries in the map.
getKey(value)Key | undefinedGets a key by its value.
getValue(key)undefined | ValueGets a value by its key.
hasKey(key)booleanChecks if the map has a key.
hasValue(value)booleanChecks if the map has a value.
keys()IterableIterator<Key>Gets all keys in the map.
set(key, value)voidSets a key-value pair in the map.
values()IterableIterator<Value>Gets all values in the map.

Links to this page: