javascript-collections-framework
    Preparing search index...

    Class LinkedHashMap<K, V>Sealed

    A map that behaves like native Map and HashMap — insertion order, SameValueZero keys (NaN is one key, -0 is stored as 0), set returning the map and keeping a present key where it is, live iteration, keys compared by value on request — and can also be read and changed at both ends: firstEntry and lastEntry, pollFirstEntry and pollLastEntry, putFirst and putLast, which insert an absent key at that end or move the present mapping there, and a live reversed() view. Each takes O(1) amortised (average for those that look up or remove).

    A map without the key, equivalence or accessOrder option keeps its mappings in a native Map until the first call that needs linked order: putFirst, putLast of a present key, lastEntry, pollLastEntry, any call through reversed(), or any call through keySet(), entrySet() or valueCollection() other than size, isEmpty and has. That call costs O(n), once; this is why the ends, putFirst, putLast, and the inserting methods of a map with maxSize (each eviction) are amortised.

    A map with accessOrder: true and neither key nor equivalence keeps its mappings in a compact form until the first call on it other than get, has, set, put (unless both maxSize and onEvict are given), delete, size, isEmpty and clear: any other method, iteration, an entry, or a call through reversed() or a view other than size and isEmpty. That call costs O(n), once, which is why those other operations are amortised for such a map. A map built with entries, or made by copy, starts in the linked form.

    With accessOrder: true, every read or write of a present key (get, getOrDefault, set, put, replace, getOrInsert, getOrInsertComputed, compute, computeIfPresent, merge, and putAll, the constructor and from for keys already present) moves its mapping to the end, so the first mapping is the least recently used. has, iteration, the views, the ends, entries, replaceAll, equals, hashing and printing never move anything. With maxSize, inserting a new key past the bound removes mappings from the front, never the one just inserted, and onEvict(value, key, map) is told about each after the call that evicted it; together they make an LRU cache.

    Iteration is live, as with native Map: mappings deleted before they are reached are skipped, mappings inserted at the end the loop is heading to are visited, those inserted at the end it started from are not, and nothing throws ConcurrentModificationError. putFirst and putLast act as a delete followed by an insertion at the new end. A move made by an access never makes an open loop return a mapping twice — on a forward loop an unvisited mapping is visited once at its new place, on a loop over reversed() it is skipped — so for (const k of map.keys()) map.get(k) ends; such a forward loop keeps a record of the mappings it returned until it is dropped.

    Changing a key's derived key or hash while it is in the map leaves lookups for it unspecified; the mapping can still be removed through the ends, a view's cursor, removeIf, removeAll, retainAll, or clear. Two maps are equal when they have the same size and each maps every key of the other to an equal value, in any order. A LinkedHashMap is not a HashMap (instanceof HashMap is false); both are maps. The class is not designed to be subclassed.

    const cache = new LinkedHashMap<string, number>({ accessOrder: true, maxSize: 2 })
    cache.set('a', 1).set('b', 2)
    cache.get('a') // 1; 'a' is now the most recently used
    cache.set('c', 3) // evicts 'b', the least recently used
    const keys = [...cache.keys()] // ['a', 'c']

    const recent = new LinkedHashMap([['x', 1], ['y', 2]])
    recent.putFirst('y', 3).toString() // "LinkedHashMap(2) {'y' => 3, 'x' => 1}"

    Type Parameters

    • K
    • V

    Implements

    Index
    • Creates a map holding each mapping of entries, set one by one in order with the options' access moves and evictions; empty when entries is omitted, undefined or null. Every item and option is checked before anything is stored; options are never taken from entries.

      Time: O(m) average for m items, plus the key or equivalence calls.

      Type Parameters

      • K
      • V

      Parameters

      • Optionalentries: Iterable<MapEntry<K, V> | readonly [K, V], any, any> | null

        [key, value] arrays, map entries, a native Map or another map.

      • Optionaloptions: LinkedHashMapOptions<K, V> | null

        key or equivalence, accessOrder, maxSize, onEvict; null means none.

      Returns LinkedHashMap<K, V>

      TypeError when entries is neither iterable nor null/undefined, an item is not an array of length 2 or a map entry, options is not an object, both key and equivalence are given, key is not a function, equivalence lacks an equals or hash function, accessOrder is not a boolean, maxSize is not a number or onEvict is not a function.

      IllegalArgumentError when maxSize is not a positive safe integer.

      Error whatever onEvict throws, after every mapping is set.

      new LinkedHashMap([['a', 1], ['b', 2]]) // LinkedHashMap(2) {'a' => 1, 'b' => 2}
      new LinkedHashMap([['a', 1], ['b', 2], ['c', 3]], { maxSize: 2 }) // {'b' => 2, 'c' => 3}
    • Creates an empty map with the given options. An object that is not iterable is read as the options.

      Time: O(1).

      Type Parameters

      • K
      • V

      Parameters

      Returns LinkedHashMap<K, V>

      TypeError when an option has the wrong type, as for the constructor with entries.

      IllegalArgumentError when maxSize is not a positive safe integer.

      const lru = new LinkedHashMap<string, string>({ accessOrder: true, maxSize: 100 })
      
    • get "[LINKED_HASH_MAP_BRAND]"(): true

      Marks instances of this class so instanceof recognises them across copies of the package. Its key is not exported, so the getter is not called directly. Time: O(1).

      Returns true

    • get "[MAP_COLLECTION_BRAND]"(): true

      Marks maps so isMapCollection recognises them across copies of the package. Its key is not exported, so the getter is not called directly. Time: O(1).

      Returns true

    • get "[SEQUENCED_MAP_BRAND]"(): true

      Marks sequenced maps across copies of the package. Its key is not exported, so the getter is not called directly. Time: O(1).

      Returns true

    • get "[toStringTag]"(): string

      'LinkedHashMap', for Object.prototype.toString. Time: O(1).

      Returns string

    • get revision(): number

      A number that changes when a mapping is added, removed or moved or a value is written (even the same value) — in access order also when a read moves a mapping — and never on a call that changes nothing. Its exact values are unspecified. Time: O(1).

      Returns number

    • get size(): number

      The number of mappings. Time: O(1).

      Returns number

    • The value-equality protocol; delegates to equals. Time: as equals.

      Parameters

      • other: unknown

      Returns boolean

    • The value-equality protocol: an order-independent combination of the mappings' hashes, the same as an equal HashMap with the same key function, the same equivalence, or neither. Values are unspecified. Time: O(n) plus the hash calls.

      Parameters

      Returns number

    • Node's inspect hook: LinkedHashMap(1) { 'a' => 1 } in console.log. Time: as toString.

      Parameters

      • depth: number | null
      • options: object
      • inspect: (value: unknown, options: object) => string

      Returns string

    • Returns a live iterator over a new [key, value] array per mapping, in order, as entries() does. new Map(linkedHashMap) copies the map this way.

      Time: O(1) to create (in access order without key or equivalence, the first call that needs linked records costs O(n), once); O(1) per step, amortised over the steps and the changes made while it is open.

      Returns IterableIterator<[K, V]>

      A new iterator.

      for (const [key, value] of map) console.log(key, value)
      
    • Removes every mapping. onEvict is not called. An open iteration starts over before the first mapping added afterwards.

      Time: O(1) with an equivalence; one native clear otherwise (at most O(n)).

      Returns void

      map.clear()
      map.size // 0
    • Maps key to fn(currentValueOrUndefined, key, map), or removes the mapping when the result is undefined, and returns the result. Writing a present key is an access.

      Time: as set, plus the call; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).

      Parameters

      • key: K

        The key.

      • fn: (value: V | undefined, key: K, map: MapCollection<K, V>) => V | undefined

        Computes the new value.

      Returns V | undefined

      The result of fn.

      TypeError when fn is not a function, or a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when fn adds or removes mappings; its changes stay and the call makes none of its own.

      Error whatever onEvict throws, after the call's changes.

      Error whatever fn throws; the call inserts and changes nothing, and changes fn made stay.

      counts.compute('a', (n) => (n ?? 0) + 1)
      
    • When key is present, maps it to fn(value, key, map), or removes the mapping when the result is undefined, and returns the result; otherwise returns undefined without calling fn. Writing the value is an access.

      Time: as set, plus the call; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).

      Parameters

      • key: K

        The key.

      • fn: (value: V, key: K, map: MapCollection<K, V>) => V | undefined

        Computes the new value.

      Returns V | undefined

      The result of fn, or undefined.

      TypeError when fn is not a function, or a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when fn adds or removes mappings.

      Error whatever fn throws; the call inserts and changes nothing, and changes fn made stay.

      stock.computeIfPresent('apple', (n) => (n > 1 ? n - 1 : undefined))
      
    • Returns whether some value is SameValueZero-equal to value. Never moves a mapping.

      Time: O(n).

      Parameters

      • value: V

        The value to look for.

      Returns boolean

      true when a mapping has that value.

      new LinkedHashMap([['a', 1]]).containsValue(1) // true
      
    • Returns a new LinkedHashMap with the same mappings, order and options — key or equivalence, accessOrder, maxSize and the same onEvict function — independent of this one. Stored keys and hashes are copied; no user function is called.

      Time: O(n).

      Returns LinkedHashMap<K, V>

      The copy.

      const copy = map.copy()
      copy.set('z', 0) // map is unchanged
    • Removes the mapping of key and returns whether there was one. onEvict is not called.

      Time: as set.

      Parameters

      • key: K

        The key.

      Returns boolean

      true when a mapping was removed.

      TypeError when a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when such a function adds or removes mappings.

      new LinkedHashMap([['a', 1]]).delete('a') // true
      
    • Returns a live iterator over a new [key, value] array per mapping, in order.

      Time: O(1) to create (in access order without key or equivalence, the first call that needs linked records costs O(n), once); O(1) per step, amortised over the steps and the changes made while it is open.

      Returns IterableIterator<[K, V]>

      A new iterator.

      [...new LinkedHashMap([['a', 1]]).entries()] // [['a', 1]]
      
    • Returns a live view of the mappings as entries, in this map's order, with this map's ends. An entry is a member when its key is present with an equal value; removing it removes the mapping; adding throws UnsupportedOperationError. Each call returns a new view.

      Time: O(1). A call through the view other than size, isEmpty and has (in access order without key or equivalence, other than size and isEmpty) needs linked order: the first such call on the map costs O(n), once, and the view's ends cost what the map's cost, amortised.

      Returns SequencedSet<MapEntry<K, V>>

      A new view, tagged LinkedHashMapEntrySet.

      for (const entry of map.entrySet()) if (entry.value < 0) entry.setValue(0)
      
    • Returns whether other is a map of the same size in which every key of this map is present with a value equal under equals, and which has no key this map lacks — whatever the order, and the same both ways round. Never moves a mapping of either map.

      Time: O(n) average, plus the lookups on both maps and the protocol methods.

      Parameters

      • other: unknown

        Any value.

      Returns boolean

      true when other is an equal map.

      ConcurrentModificationError when a value's equals changes the structure of other while it is compared (values are compared as equals(otherValue, thisValue)).

      new LinkedHashMap([['a', 1], ['b', 2]]).equals(new HashMap([['b', 2], ['a', 1]])) // true
      
    • Returns the entry of the first mapping, or undefined when the map is empty. Never moves a mapping and calls no user function. The entry is live: it reads the map's current value of its key.

      Time: O(1) amortised.

      Returns MapEntry<K, V> | undefined

      A live entry, or undefined.

      new LinkedHashMap([['a', 1], ['b', 2]]).firstEntry()?.key // 'a'
      
    • Calls action(value, key, map) for each mapping in order, with this set to thisArg, as native Map does. Mappings deleted before they are reached are skipped; mappings added at the end during the loop are visited.

      Time: O(n) plus the calls.

      Parameters

      • action: (value: V, key: K, map: MapCollection<K, V>) => void

        Called with each value, its key and the map.

      • OptionalthisArg: unknown

        The this value for action.

      Returns void

      TypeError when action is not a function.

      Error whatever onEvict throws for mappings evicted by action, after the loop.

      map.forEach((value, key) => console.log(key, value))
      
    • Returns the value mapped to a key equal to key, or undefined when there is none. In access order, a present mapping moves to the end.

      Time: O(1) average, plus one key or hash call and the equals calls.

      Parameters

      • key: K

        The key to look up (-0 is read as 0).

      Returns V | undefined

      The value, or undefined.

      TypeError when a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when such a function adds or removes mappings.

      new LinkedHashMap([['a', 1]]).get('a') // 1
      
    • Returns the value mapped to key when the key is present (even when that value is undefined), and fallback otherwise. In access order, a present mapping moves to the end.

      Time: as get; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).

      Type Parameters

      • D

      Parameters

      • key: K

        The key to look up.

      • fallback: D

        The value to return when the key is absent.

      Returns V | D

      The mapped value, or fallback.

      TypeError when a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when such a function adds or removes mappings.

      new LinkedHashMap([['a', 1]]).getOrDefault('b', 0) // 0
      
    • Returns the value of key when present (in access order, moving it to the end); otherwise maps key to value at the end and returns value, as native Map.prototype.getOrInsert does.

      Time: as set; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).

      Parameters

      • key: K

        The key.

      • value: V

        The value to insert when the key is absent.

      Returns V

      The mapped value.

      TypeError when a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when such a function adds or removes mappings.

      Error whatever onEvict throws, after the mapping is set.

      groups.getOrInsert('a', []).push(1)
      
    • Returns the value of key when present (in access order, moving it to the end), without calling fn; otherwise calls fn(key), maps key to its result and returns it. If fn inserted the key itself, that mapping's value is overwritten in place, as an access.

      Time: as set, plus the call; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).

      Parameters

      • key: K

        The key.

      • fn: (key: K) => V

        Computes the value to insert, called with this undefined.

      Returns V

      The mapped value.

      TypeError when fn is not a function (even when the key is present), or a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when a key, equals or hash function adds or removes mappings.

      Error whatever onEvict throws, after the mapping is set.

      Error whatever fn throws; the call inserts and changes nothing, and changes fn made stay.

      cache.getOrInsertComputed(id, (id) => load(id))
      
    • Returns whether a key equal to key is present. Never moves a mapping.

      Time: as get.

      Parameters

      • key: K

        The key to look for.

      Returns boolean

      true when the key is present.

      TypeError when a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when such a function adds or removes mappings.

      new LinkedHashMap([[Number.NaN, 1]]).has(Number.NaN) // true
      
    • Returns whether the map has no mappings.

      Time: O(1).

      Returns boolean

      size === 0.

      new LinkedHashMap().isEmpty() // true
      
    • Returns a live iterator over the keys in order.

      Time: O(1) to create (in access order without key or equivalence, the first call that needs linked records costs O(n), once); O(1) per step, amortised over the steps and the changes made while it is open.

      Returns IterableIterator<K>

      A new iterator.

      [...new LinkedHashMap([['a', 1]]).keys()] // ['a']
      
    • Returns a live view of the keys in this map's order, under its key equality, with this map's ends. Removing a key removes its mapping; add, addFirst and addLast throw UnsupportedOperationError. Each call returns a new view.

      Time: O(1). A call through the view other than size, isEmpty and has (in access order without key or equivalence, other than size and isEmpty) needs linked order: the first such call on the map costs O(n), once, and the view's ends cost what the map's cost, amortised.

      Returns SequencedSet<K>

      A new view, tagged LinkedHashMapKeySet.

      map.keySet().getLast() // the key of the last mapping
      
    • Returns the entry of the last mapping, or undefined when the map is empty. Never moves a mapping and calls no user function.

      Time: O(1) amortised (the first call that needs linked order costs O(n), once).

      Returns MapEntry<K, V> | undefined

      A live entry, or undefined.

      new LinkedHashMap([['a', 1], ['b', 2]]).lastEntry()?.value // 2
      
    • Maps key to value at the end when it is absent; otherwise to fn(old, value, key, map), removing the mapping when that result is undefined. Returns the stored value, or undefined when the mapping was removed. Writing a present key is an access.

      Time: as set, plus the call; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).

      Parameters

      • key: K

        The key.

      • value: V

        The value to store, or to combine with the present one.

      • fn: (old: V, value: V, key: K, map: MapCollection<K, V>) => V | undefined

        Combines the present value with value.

      Returns V | undefined

      The stored value, or undefined.

      TypeError when fn is not a function, or a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when fn adds or removes mappings.

      Error whatever onEvict throws, after the mapping is set.

      Error whatever fn throws; the call inserts and changes nothing, and changes fn made stay.

      for (const word of words) counts.merge(word, 1, (n, one) => n + one)
      
    • Removes the first mapping and returns its entry, or returns undefined when the map is empty. The entry still reads its value; setValue on it throws IllegalStateError until the key is set again. No user function is called and onEvict is not.

      Time: O(1) amortised average.

      Returns MapEntry<K, V> | undefined

      The entry of the removed mapping, or undefined.

      const oldest = cache.pollFirstEntry()
      
    • Removes the last mapping and returns its entry, or returns undefined when the map is empty. No user function is called and onEvict is not.

      Time: O(1) amortised average (the first call that needs linked order costs O(n), once).

      Returns MapEntry<K, V> | undefined

      The entry of the removed mapping, or undefined.

      new LinkedHashMap([['a', 1], ['b', 2]]).pollLastEntry()?.key // 'b'
      
    • Maps key to value, as set does, and returns the previous value, or undefined when the key was absent.

      Time: as set; O(1) amortised average with accessOrder, maxSize and onEvict (the first call that needs linked records costs O(n), once).

      Parameters

      • key: K

        The key.

      • value: V

        The value.

      Returns V | undefined

      The previous value, or undefined.

      TypeError when a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when such a function adds or removes mappings.

      Error whatever onEvict throws, after the mapping is set.

      new LinkedHashMap([['a', 1]]).put('a', 2) // 1
      
    • Sets every mapping of entries in order, each as one set with its access move and eviction. The whole argument is read and checked first, so map.putAll(map) is safe; evictions are reported to onEvict once, after the last pair.

      Time: O(m) average for m items, plus the calls; O(m) amortised average with maxSize or in access order (the first call that needs linked records costs O(n), once).

      Parameters

      • entries: Iterable<MapEntry<K, V> | readonly [K, V]>

        [key, value] arrays, map entries, a native Map or a map.

      Returns void

      TypeError when entries is not iterable, an item is not an array of length 2 or a map entry, or a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when such a function adds or removes mappings.

      Error whatever onEvict throws, after the mappings are set.

      map.putAll(new Map([['a', 1], ['b', 2]]))
      
    • Maps key to value at the front: inserts the mapping there when the key is absent, or moves the present mapping there (keeping its stored key) and writes its value. Not an access. With maxSize, a new key can evict from the front, never itself.

      Time: O(1) amortised average, plus one key or hash call and the equals calls (the first call that needs linked order costs O(n), once).

      Parameters

      • key: K

        The key.

      • value: V

        The value.

      Returns this

      The map.

      TypeError when a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when such a function adds or removes mappings; nothing is inserted or moved.

      Error whatever onEvict throws, after the mapping is placed.

      new LinkedHashMap([['a', 1], ['b', 2]]).putFirst('b', 3) // LinkedHashMap(2) {'b' => 3, 'a' => 1}
      
    • Maps key to value at the end: inserts the mapping there when the key is absent, or moves the present mapping there (keeping its stored key) and writes its value. Not an access.

      Time: O(1) amortised average, plus one key or hash call and the equals calls (the first call that needs linked order costs O(n), once).

      Parameters

      • key: K

        The key.

      • value: V

        The value.

      Returns this

      The map.

      TypeError when a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when such a function adds or removes mappings; nothing is inserted or moved.

      Error whatever onEvict throws, after the mapping is placed.

      new LinkedHashMap([['a', 1], ['b', 2]]).putLast('a', 3) // LinkedHashMap(2) {'b' => 2, 'a' => 3}
      
    • Removes the mapping of key and returns its value, or undefined when there was none.

      Time: as set; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).

      Parameters

      • key: K

        The key.

      Returns V | undefined

      The removed value, or undefined.

      TypeError when a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when such a function adds or removes mappings.

      new LinkedHashMap([['a', 1]]).remove('a') // 1
      
    • Replaces the value of key only when the key is present (in access order, moving it to the end), and returns the previous value, or undefined.

      Time: as set; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).

      Parameters

      • key: K

        The key.

      • value: V

        The new value.

      Returns V | undefined

      The previous value, or undefined.

      TypeError when a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when such a function adds or removes mappings.

      new LinkedHashMap([['a', 1]]).replace('b', 2) // undefined; nothing is added
      
    • Replaces each value with fn(value, key, map), in order. Never moves a mapping. Values replaced before an error stay.

      Time: O(n) plus the calls.

      Parameters

      Returns void

      TypeError when fn is not a function.

      ConcurrentModificationError when fn adds or removes mappings.

      prices.replaceAll((price) => price * 2)
      
    • Returns a live view of this map in the opposite order, tagged ReversedLinkedHashMap. Changes through either show in both; its ends are this map's ends swapped, and a key it inserts goes to its end, this map's front. Access moves and evictions act on this map as usual. Reversing the view returns this map.

      Time: O(1). Every call through the view needs linked order: the first such call on the map costs O(n), once, and the view's operations cost what the map's cost, amortised.

      Returns SequencedMap<K, V>

      The reversed view.

      const newestFirst = map.reversed()
      for (const [key] of newestFirst) console.log(key)
    • Maps key to value and returns the map, so calls chain. A new key goes to the end; a present key keeps its stored key object and its position (in access order it moves to the end) and only the value is replaced. With maxSize, a new key can evict from the front.

      Time: O(1) average, plus one key or hash call and the equals calls; O(1) amortised average with maxSize.

      Parameters

      • key: K

        The key (-0 is stored as 0).

      • value: V

        The value.

      Returns this

      The map.

      TypeError when a key, equals or hash function returns an invalid result.

      ConcurrentModificationError when such a function adds or removes mappings; the map keeps those changes and stores nothing itself.

      Error whatever onEvict throws, after the mapping is set.

      new LinkedHashMap<string, number>().set('a', 1).set('b', 2) // LinkedHashMap(2) {'a' => 1, 'b' => 2}
      
    • Returns a new array of [key, value] arrays in order, so JSON.stringify writes the map as pairs.

      Time: O(n).

      Returns [K, V][]

      A new array.

      JSON.stringify(new LinkedHashMap([['a', 1]])) // '[["a",1]]'
      
    • Returns the class name, size and mappings in order, e.g. LinkedHashMap(2) {'a' => 1, 'b' => 2}; a map that contains itself prints as [Circular].

      Time: O(length of the output) for flat contents.

      Returns string

      The text.

      String(new LinkedHashMap([['a', 1]])) // "LinkedHashMap(1) {'a' => 1}"
      
    • Returns a live view of the values in this map's order, compared with SameValueZero, with this map's ends. delete(v) removes the first mapping with that value; removeAll, retainAll and removeIf every matching mapping; adding throws UnsupportedOperationError. The view equals only itself. Each call returns a new view.

      Time: O(1). A call through the view other than size, isEmpty and has (in access order without key or equivalence, other than size and isEmpty) needs linked order: the first such call on the map costs O(n), once, and the view's ends cost what the map's cost, amortised.

      Returns SequencedCollection<V>

      A new view, tagged LinkedHashMapValues.

      map.valueCollection().removeIf((v) => v === 0)
      
    • Returns a live iterator over the values in order.

      Time: O(1) to create (in access order without key or equivalence, the first call that needs linked records costs O(n), once); O(1) per step, amortised over the steps and the changes made while it is open.

      Returns IterableIterator<V>

      A new iterator.

      [...new LinkedHashMap([['a', 1]]).values()] // [1]
      
    • Returns whether value is a LinkedHashMap, including one created by another copy of the library with the same major version. Its reversed view is not one.

      Time: O(1).

      Parameters

      • value: unknown

        The value on the left of instanceof.

      Returns boolean

      true when value is a LinkedHashMap.

      new LinkedHashMap() instanceof LinkedHashMap // true
      
    • Returns a new map of the mappings of entries, set one by one in order with the options' access moves and evictions. Every item and option is checked before anything is stored.

      Time: O(m) average for m items, plus the key or equivalence calls.

      Type Parameters

      • K
      • V

      Parameters

      • entries: Iterable<readonly [K, V] | MapEntry<K, V>>

        [key, value] arrays, map entries, a native Map or another map.

      • Optionaloptions: LinkedHashMapOptions<K, V> | null

        As for the constructor; null means none.

      Returns LinkedHashMap<K, V>

      A new map.

      TypeError when entries is not iterable (null and undefined included), an item is not a pair or an entry, or an option has the wrong type.

      IllegalArgumentError when maxSize is not a positive safe integer.

      Error whatever onEvict throws, after every mapping is set.

      LinkedHashMap.from(Object.entries({ a: 1, b: 2 })) // LinkedHashMap(2) {'a' => 1, 'b' => 2}