Function objUpdate

  • Updates the value of a specific key in an object using a callback function.

    Type Parameters

    • V

      The type of the values in the object.

    Parameters

    • obj: Record<ObjectKey, V>

      The object to update.

    • key: ObjectKey

      The key of the value to update.

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

      The function to generate the new value. It receives the current value and the key as arguments.

        • (value, key): V
        • Parameters

          Returns V

    Returns V

    The new value.

    Example

    objUpdate({ a: 1, b: 2 }, 'a', (value, key) => value + 1);;
    //=> { a: 2, b: 2 }

Generated using TypeDoc