Skip to content

Function: set()

ts
function set<T>(
   object, 
   path, 
   value): T;

Sets a nested value on an object by path. 通过路径为对象设置嵌套值。

Type Parameters

Type ParameterDescription
T extends Record<PropertyKey, unknown>The object type / 对象类型

Parameters

ParameterTypeDescription
objectTThe target object / 目标对象
pathstring | readonly PropertyKey[]The set path / 设置路径
valueunknownThe 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

Released under the MIT License.