Function unset

  • Removes the property at the given path of the object.

    Parameters

    • obj: any

      The object to modify.

    • path: PropertyKey | readonly PropertyKey[]

      The path of the property to unset.

    Returns boolean

    • Returns true if the property is deleted, else false.
    const obj = { a: { b: { c: 42 } } };
    unset(obj, 'a.b.c'); // true
    console.log(obj); // { a: { b: {} } }
    const obj = { a: { b: { c: 42 } } };
    unset(obj, ['a', 'b', 'c']); // true
    console.log(obj); // { a: { b: {} } }