Puts a value into a nested structure via "dot-notation" (mutates object). Traverses nested objects and arrays, creating new nested objects/arrays as needed.
a mutable object
a dot-notation path
a value
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 }] } Copy
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 }] }
Puts a value into a nested structure via "dot-notation" (mutates object). Traverses nested objects and arrays, creating new nested objects/arrays as needed.