Function objForEach

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

    Type Parameters

    • T

      The type of the object's properties.

    Parameters

    • object: Record<string, T>

      The object to iterate over.

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

      The function to apply to each keyvalue pair.

        • (value, key): void
        • Parameters

          • value: T
          • key: string

          Returns void

    • getKeys: ((obj) => Iterable<string>) = Object.keys

      The function to retrieve the keys of the object.

        • (obj): Iterable<string>
        • Parameters

          • obj: Record<string, T>

          Returns Iterable<string>

    Returns typeof object

    The original object.

    Example

    const myObject = { a: 1, b: 2, c: 3 };
    objForEach(myObject, (value, key) => {
    //=> ${key}: ${value}
    });

Generated using TypeDoc