javascript-collections-framework
    Preparing search index...

    Function mapOf

    • Returns an immutable map of entries, as new Map builds it: keys iterate in first-seen order, and a repeated key keeps its first position and first key object and takes its last value. Keys are compared with SameValueZero (-0 is stored as 0, NaN is one key); null and undefined are stored as keys and values. Every method that would change the map, its views or its entries throws UnsupportedOperationError.

      For many entries, use copyOfMap: spreading a large array into a call fails at the call site.

      Time: O(n) average for n entries.

      Type Parameters

      • K
      • V

      Parameters

      • ...entries: (readonly [K, V] | MapEntry<K, V>)[]

        [key, value] arrays or map entries.

      Returns ReadonlyMapCollection<K, V>

      An immutable map.

      TypeError when an item is neither an array of length 2 nor a map entry.

      const limits = mapOf(['small', 10], ['large', 100])
      limits.get('large') // 100
      String(limits) // "ImmutableMap(2) {'small' => 10, 'large' => 100}"