Function mapValues

  • Map the values of an object using a mapping function

    Returns

    obj with its values mapped using mapFn

    Example

    const counts = mapValues({ a: 1, b: 2, c: 3 }, x => x + 1)
    counts === { a: 2, b: 3, c: 4 }

    Example

    const lengths = mapValues({ a: 'cat', b: 'elephant', c: 'mouse' }, a => a.length)
    lengths === { a: 3, b: 8, c: 5 }

    Type Parameters

    • TMapped

    • TObj extends Record<PropertyKey, any>

    Parameters

    • obj: TObj

      the object to map values of

    • mapFn: ((t) => TMapped)

      the mapping function

        • (t): TMapped
        • Parameters

          • t: TObj[keyof TObj]

          Returns TMapped

    Returns {
        [k in string | number | symbol]: TMapped
    }

Generated using TypeDoc