Function getMultiple

Returns first found value at given list of paths of given object. Will return and stop at undefined if found! If nothing is found then default value (required to pass) will be returned.

This is still too dynamic in nature to get full TypeScript support. Properties are not typed, return type is unknown. If your data access is statically known there is no need to use this function, just use object.property syntax with optional chaining.

get - for base usage example with single path only

getMultiple(obj, 5, "details.error.message", ["error", "message"], "errorMessage")
// will look for obj.details.error.message - if path does not exist
// will look for obj.error.message - if not defined
// will look for obj.errorMessage - if not defined
// will return 5
  • Parameters

    • source: GetMultipleSource

      source object to search in

    • defaultValue: unknown

      default value to return if nothing is found

    • Rest...paths: (string | string[])[]

      paths defined as dot-separated properties names or array of properties name

    Returns unknown

    • found value or default value