std
    Preparing search index...

    Function toMap

    • Maps the provided array into a map

      Type Parameters

      • T
      • K
      • V

      Parameters

      • arr: T[]

        Array of items to be entered into a map

      • fn: (item: T, index: number) => [key: K, value: V]

        A mapping function to transform each item into a key value pair

      Returns Map<K, V>

      const map = toMap([5, 4, 3, 2, 1], (item, i) => [i, item]);

      console.log(map); // Map(5) { 0 => 5, 1 => 4, 2 => 3, 3 => 2, 4 => 1 }