Tweakr
    Preparing search index...

    Function mapValues

    • Creates a new object with the same keys as the input object, where each value is the result of applying the provided function to the original value.

      Type Parameters

      • T extends object
      • U

      Parameters

      • obj: T

        The object whose values will be transformed.

      • fn: (value: T[keyof T], key: keyof T) => U

        A function that transforms each value of the object.

      Returns { [K in string | number | symbol]: U }

      A new object with transformed values.

      const obj = { a: 1, b: 2 };
      const doubled = mapValues(obj, (value) => value * 2);
      console.log(doubled); // { a: 2, b: 4 }

      1.1.0