Function mapKeys

  • Calls a function for each key in an object and stores the results in an array.

    Type Parameters

    • T extends object

    • R

    Parameters

    • obj: T

      The object to iterate over.

    • callback: (<K extends string | number | symbol>(key: K, obj: T) => R)

      The function to call for each key where the first argument is the key and the second is obj.

        • <K extends string | number | symbol>(key: K, obj: T): R
        • Type Parameters

          • K extends string | number | symbol

          Parameters

          • key: K
          • obj: T

          Returns R

    Returns R[]

    An array containing the results.

    Remarks

    Keys are the object's own enumerable string-keyed property names, the same as those returned by Object.keys().

    Example

    Basic Usage

    const result = mapKeys({ a: 1, b: 2, c: 3 }, (key, obj) => {
    key // type: 'a', 'b', 'c'
    return obj[key]
    }) // type: number[]
    console.log(result) // [1, 2, 3]

Generated using TypeDoc