Function objMapMutable

  • Applies a callback function to each key-value pair in an object and mutates the object.

    Type Parameters

    • T

      The type of the properties in the object.

    Parameters

    • object: Record<string, T>

      The object to be mapped.

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

      The callback function to apply to each valuekey pair.

        • (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 typeof object

    The mutated object.

    Example

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

Generated using TypeDoc