Set a value at a path in an object.
The object to set the value in.
The path to set the value at.
The value to set.
Optional
The options for setting the value.
const obj = { a: { b: { c: 1 } } };// Set the value at the path "a.b.c" to 2.setAtPath(obj, "a.b.c", 2);console.log(obj); // { a: { b: { c: 2 } } }// Add a new value at the path "a.b.d" with the value 3.setAtPath(obj, "a.b.d", 3);console.log(obj); // { a: { b: { c: 2, d: 3 } } } Copy
const obj = { a: { b: { c: 1 } } };// Set the value at the path "a.b.c" to 2.setAtPath(obj, "a.b.c", 2);console.log(obj); // { a: { b: { c: 2 } } }// Add a new value at the path "a.b.d" with the value 3.setAtPath(obj, "a.b.d", 3);console.log(obj); // { a: { b: { c: 2, d: 3 } } }
Set a value at a path in an object.