Skip to content

Function: get()

ts
function get(
   obj: any, 
   path: string | string[], 
   defaultValue?: any): any;

Defined in: src/utils/get.ts:16

Get a value from a nested object using a dot-separated path.

Parameters

ParameterTypeDescription
objanyThe source object.
pathstring | string[]A dot-separated string or array of keys.
defaultValue?anyThe value to return if the path does not exist.

Returns

any

The value at the path, or the default value.

Example

ts
const order = { customer: { name: 'Alice', address: { city: 'Portland' } } };
get(order, 'customer.address.city'); // 'Portland'
get(order, 'customer.phone', 'N/A'); // 'N/A'

Matterway Assistant SDK Documentation