@bnidev/js-utils
    Preparing search index...

    Function setNestedValue

    • Sets a value at a nested path in an object.

      Type Parameters

      • T extends object

        The type of the object.

      Parameters

      • obj: T

        The object to set the value in.

      • path: string

        The dot-notation path (e.g., 'a.b.c').

      • value: unknown

        The value to set.

      Returns T

      A new object with the value set at the specified path.

      // ES Module
      import { setNestedValue } from '@bnidev/js-utils'

      // CommonJS
      const { setNestedValue } = require('@bnidev/js-utils')
      const obj = { a: { b: 1 } }
      const result = setNestedValue(obj, 'a.c', 2)
      // result: { a: { b: 1, c: 2 } }