Sets a value at a nested path in an object.
The type of the object.
The object to set the value in.
The dot-notation path (e.g., 'a.b.c').
The value to set.
A new object with the value set at the specified path.
// ES Moduleimport { setNestedValue } from '@bnidev/js-utils'// CommonJSconst { setNestedValue } = require('@bnidev/js-utils') Copy
// ES Moduleimport { setNestedValue } from '@bnidev/js-utils'// CommonJSconst { setNestedValue } = require('@bnidev/js-utils')
const obj = { a: { b: 1 } }const result = setNestedValue(obj, 'a.c', 2)// result: { a: { b: 1, c: 2 } } Copy
const obj = { a: { b: 1 } }const result = setNestedValue(obj, 'a.c', 2)// result: { a: { b: 1, c: 2 } }
Sets a value at a nested path in an object.