Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.
The type of the object.
The object to modify.
The path of the property to set.
The value to set.
// Set a value in a nested objectconst obj = { a: { b: { c: 3 } } };set(obj, 'a.b.c', 4);console.log(obj.a.b.c); // 4 Copy
// Set a value in a nested objectconst obj = { a: { b: { c: 3 } } };set(obj, 'a.b.c', 4);console.log(obj.a.b.c); // 4
// Set a value in an arrayconst arr = [1, 2, 3];set(arr, 1, 4);console.log(arr[1]); // 4 Copy
// Set a value in an arrayconst arr = [1, 2, 3];set(arr, 1, 4);console.log(arr[1]); // 4
// Create non-existent path and set valueconst obj = {};set(obj, 'a.b.c', 4);console.log(obj); // { a: { b: { c: 4 } } } Copy
// Create non-existent path and set valueconst obj = {};set(obj, 'a.b.c', 4);console.log(obj); // { a: { b: { c: 4 } } }
Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.
Template: T
The type of the object.
Param: obj
The object to modify.
Param: path
The path of the property to set.
Param: value
The value to set.
Returns
Example
Example
Example