Appearance
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
| Parameter | Type | Description |
|---|---|---|
obj | any | The source object. |
path | string | string[] | A dot-separated string or array of keys. |
defaultValue? | any | The 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'