@trashpanda001/helpers
    Preparing search index...

    Function putIn

    • Puts a value into a nested structure via "dot-notation" (mutates object). Traverses nested objects and arrays, creating new nested objects/arrays as needed.

      Parameters

      • object: unknown[] | Record<string, unknown>

        a mutable object

      • path: string

        a dot-notation path

      • value: unknown

        a value

      Returns void

      import { putIn } from "@trashpanda001/helpers/object"

      const x = { a: { b: { c: 42 } } }
      putIn(x, "a.b.c", { d: 123 })
      // x = { a: { b: { c: { d: 123 } } }

      const y = { a: [{ c: 42 }] }
      putIn(y, "a.1", { c: 100 })
      // y = { a: [{ c: 42 }, { c: 100 }] }