Function: get()
ts
function get<T>(
object,
path,
defaultValue?): unknown;Safely gets a nested value from an object by path. 通过路径安全地获取对象中的嵌套值。
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
T | undefined | The fallback value type / 兜底值类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
object | unknown | The source object / 源对象 |
path | string | readonly PropertyKey[] | The access path / 访问路径 |
defaultValue? | T | The fallback value returned when the path does not exist / 路径不存在时返回的兜底值 |
Returns
unknown
The found value or the fallback value / 找到的值或兜底值
Example
ts
get({ a: { b: 2 } }, 'a.b')
// => 2Since
1.2.0