Function objMap

  • Maps over the values of an object and returns a new object with the mapped values.

    Type Parameters

    • T

      The type of the values in the input object.

    Parameters

    • object: Record<string, T>

      The object to map over.

    • callback: ((value, key) => T)

      The mapping function to apply to each value.

        • (value, key): T
        • Parameters

          • value: T
          • key: string

          Returns T

    • getKeys: ((obj) => Iterable<string>) = Object.keys

      The function used to get the keys of the object.

        • (obj): Iterable<string>
        • Parameters

          • obj: Record<string, T>

          Returns Iterable<string>

    Returns Record<string, T>

    A new object with the same keys as the input object, but with each value transformed by the callback function.

    Example

    const object = { a: 1, b: 2, c: 3 }
    const callback = (value: number, key: string) => value * 2
    objMap(object, callback) //=> { a: 2, b: 4, c: 6 }

Generated using TypeDoc