Function property

  • Creates a function that returns the value at a given path of an object.

    Parameters

    • path: PropertyKey | readonly PropertyKey[]

      The path of the property to get.

    Returns ((object: unknown) => any)

    • Returns a new function that takes an object and returns the value at the specified path.
      • (object): any
      • Parameters

        • object: unknown

        Returns any

    const getObjectValue = property('a.b.c');
    const result = getObjectValue({ a: { b: { c: 3 } } });
    console.log(result); // => 3
    const getObjectValue = property(['a', 'b', 'c']);
    const result = getObjectValue({ a: { b: { c: 3 } } });
    console.log(result); // => 3