Function toMapBy

  • Creates a map from the own entries of an object.

    Since

    13.0.0

    See

    toMap

    Returns

    Map created from the object.

    Example

    toMapBy({a: 1, b: 4, c: 5}, key => { return { key }; }, value => value * 2)
    // => Map{{key: "a"}: 2, {key: "b"}: 8, {key: "a"}: 10}

    toMapBy([1, 2, 3], (_key, value) => value, (_key, value) => value * 2)
    // => Map{1: 2, 2: 4, 3: 6}

    Type Parameters

    • TValue

    • UKey

    • VInitialValue

    Parameters

    • object: Record<PropertyKey, VInitialValue> | ArrayLike<VInitialValue>

      Object to use.

    • keyMapper: ((key: string, val: VInitialValue) => UKey)

      Function mapping an object key to a map key.

        • (key: string, val: VInitialValue): UKey
        • Parameters

          • key: string
          • val: VInitialValue

          Returns UKey

    • valueMapper: ((key: string, value: VInitialValue) => TValue)

      Function mapping an object value to a map value.

        • (key: string, value: VInitialValue): TValue
        • Parameters

          • key: string
          • value: VInitialValue

          Returns TValue

    Returns Map<UKey, TValue>

Generated using TypeDoc