Function objForEachKey

  • Calls the provided callbackFn function once for each key in an object. This is equivelent to arrForEach(Object.keys(theObject), callbackFn) or if not using the array helper Object.keys(theObject).forEach(callbackFn) except that this helper avoid creating a temporary of the object keys before iterating over them and like the arrForEach helper you CAN stop or break the iteration by returning -1 from the callbackFn function.

    Type Parameters

    • T

      The object type

    Parameters

    • theObject: T
    • callbackfn: ((key: string, value: T[keyof T]) => number | void)

      A function that accepts up to two arguments, the key name and the current value of the property represented by the key.

        • (key, value): number | void
        • Parameters

          • key: string
          • value: T[keyof T]

          Returns number | void

    • OptionalthisArg: any

      [Optional] An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, null or undefined the object will be used as the this value.

    Returns void

    function performAction<T>(target: T, source: any) {
    if (!isNullOrUndefined(source)) {
    objForEachKey(source, (key, value) => {
    // Set the target with a reference to the same value with the same name
    target[key] = value;
    });
    }

    return target;
    }