Skip to content

Function.unset

github-actions[bot] edited this page Nov 18, 2026 · 13 revisions

umt / unset

Function: unset()

unset<T>(object, path): T

Defined in: Object/unset.ts:62

Removes the property at a deeply nested path without mutating the input. Uses the same path parsing as get, set and has.

Plain objects and arrays along the path are shallow-copied, while untouched branches keep their references. Removing an array index removes the element and shifts the following elements. Any other value on the path, or a missing segment, stops the traversal and leaves the rest unchanged.

Type Parameters

T

T extends object

Type of the source object

Parameters

object

T

Source object (not mutated)

path

string | string[]

Dot-separated string or path segments array

Returns

T

A new object without the property at the path

Remarks

Prototype pollution warning: This function does not filter out prototype-polluting keys (__proto__, constructor, prototype). Sanitize user-controlled paths before calling.

Example

unset({ a: { b: 1, c: 2 } }, "a.b"); // { a: { c: 2 } }
unset({ a: [1, 2, 3] }, ["a", "1"]); // { a: [1, 3] }
unset({ a: 1 }, "x.y"); // { a: 1 }

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally