• Returns the value at given path of given object. If path is not found then default value is returned. No exceptions are thrown when undefined/null value gets in the way.

    Example

    get(object, "deep.property") // equals to safe object.deep.property

    Example

    get(object, ["deep", "property"]) // same as above
    

    Example

    get(object, "deep[0].property")
    // equals to:
    object["deep[0]"].property
    // not:
    object.deep[0].property

    Example

    get(object, "very.deep.property", 5) // if object.very.deep has also property property then it value will be returned, even if undefined // else 5 will be returned

    Returns

    • found value or default value

    Parameters

    • source: Source

      source object to search in

    • property: string | string[]

      path to the expected value written as dot-separated property names or array with property names. Use Array when your keys includes dots. Keys are treated literally, no parsing is done on keys.

    • Optional defaultValue: unknown = undefined

      value to return if path is not found. If path is found, but the value is undefined - default value will NOT be used, use get(...) || default instead

    Returns unknown

Generated using TypeDoc