unset()
unset<
T>(object,path):T
Removes the property at path of object, returning a new object (immutable).
DEPRECATED
Use destructuring or omit for immutable property removal.
Type Parameters
T: T extends object
The type of the input object.
Parameters
object: T
The object to modify.
path: string | (string | number | symbol)[]
The path of the property to unset.
Returns: T
A new object with the property removed.
See Also
Since
2.0.0
Also known as
dissocPath (Ramda) · unset (Lodash, es-toolkit) · ❌ (Remeda, Radashi, Effect, Modern Dash, Antfu)
Example
const object = { a: { b: { c: 3 } } };
// ❌ Deprecated approach
unset(object, 'a.b.c');
// => { a: { b: {} } }
// ✅ Recommended approach (for shallow properties)
const { c, ...rest } = object.a.b;
// rest = {}
// ✅ Recommended approach (for nested properties)
import { omit } from '@pithos/arkhe/object/omit';
// or use immutability-helper, immer, etc.
How it works?
Removes property at path, returning new object (immutable).
Processing Flow
Common Inputs
| Object | Path | Result |
|---|---|---|
{a: {b: {c: 3}}} | 'a.b.c' | {a: {b: {}}} |
{x: 1, y: 2} | 'x' | {y: 2} |
Deprecated: Use destructuring or
omitfor immutable removal.
Use Cases
Remove nested property 📌
Remove property at path immutably.
// For shallow properties
const { propToRemove, ...rest } = obj;
// For nested, use omit or destructuring
import { omit } from '@pithos/arkhe';
Clean object
Remove unwanted properties.
const { password, ...safeUser } = user;
Remove nested state property immutably
Delete a deeply nested property in a state tree without mutating the original. Essential pattern for Redux/Zustand reducers handling deletion actions.
const state = {
users: {
"u-1": { name: "Alice", preferences: { theme: "dark", notifications: true } },
"u-2": { name: "Bob", preferences: { theme: "light" } },
},
};
// Remove a specific user's notification preference
const newState = unset(state, "users.u-1.preferences.notifications");
// state.users["u-1"].preferences.notifications still exists (original untouched)
// newState.users["u-1"].preferences => { theme: "dark" }
Deprecated: Use destructuring or