Function setValueAtPath

  • Returns a new object with the value set at the specified path.

    Type Parameters

    • T extends object
    • P extends string

    Parameters

    • path: P
    • value: DeepValue<T, P>
    • obj: T
    • separator: string = '.'

    Returns T

    Example

    // returns { foo: 'rab' }
    setValueAtPath('foo', 'rab', { foo: 'bar' });
    // returns { a: { b: { c: { d: 'e' } } } }
    setValueAtPath('a.b.c.d', 'e', { a: { b: { c: { d: 'f' } } } });