• Set a value at a path in an object.

    Type Parameters

    • T

    Parameters

    • obj: Record<string, unknown>

      The object to set the value in.

    • path: string

      The path to set the value at.

    • value: T

      The value to set.

    • Optionaloptions: SetAtPathOptions

      The options for setting the value.

    Returns void

    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 } } }