Function getField

Gets the data at path in object. Assumes '.' separates each segment of path.

getField({ name: { first: `Thom`, last: `Yorke` }}, `name.first`); // 'Thom'
getField({ colours: [`red`, `green`, `blue` ]}, `colours.1`); // `green`

Returns undefined if path could not be resolved.

Throws if:

  • path is not a string or empty
  • object is undefined or null
  • Type Parameters

    • V

    Parameters

    • object: Record<string, any>
    • path: string

    Returns Result<V>