Function: set()
ts
function set<T>(
object,
path,
value): T;Sets a nested value on an object by path. 通过路径为对象设置嵌套值。
Type Parameters
| Type Parameter | Description |
|---|---|
T extends Record<PropertyKey, unknown> | The object type / 对象类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
object | T | The target object / 目标对象 |
path | string | readonly PropertyKey[] | The set path / 设置路径 |
value | unknown | The value to set / 要设置的值 |
Returns
T
The same object after mutation / 设置后的原对象
Example
ts
set({ a: 1 }, 'b.c', 3)
// => { a: 1, b: { c: 3 } }Since
1.2.0