javascript-collections-framework
    Preparing search index...

    Function copyOfMap

    • Returns an immutable map of the mappings of entries — a library map, a native Map, or an iterable of [key, value] arrays or map entries — built as mapOf builds it, deciding key sameness by options as a HashMap does. Every item is read and checked before any key, equals or hash call. Given a map this function or mapOf returned with the same key or equivalence (or none on both), it may return that map.

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

      Type Parameters

      • K
      • V

      Parameters

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

        The mappings.

      • Optionaloptions: HashMapOptions<K> | null

        key or equivalence; null or undefined means none.

      Returns ReadonlyMapCollection<K, V>

      An immutable map.

      TypeError when entries is not iterable (null and undefined included), an item is neither an array of length 2 nor a map entry, or the options are invalid (as for copyOfSet).

      const settings = copyOfMap(new Map([['theme', 'dark']]))
      settings.get('theme') // 'dark'