🎯 Removes a property at a specific path of an object.
Warning
Mutable: This function mutates the original object. Use toUnset for an immutable version.
Info
When used on arrays, it creates a sparse array by deleting the element at the index without shifting other elements.
Syntax
TypeScript
import { unset } from '@opentf/std'; unset<T>( obj: T, path: string | unknown[], ): T
Parameters
obj: The object or array to modify.path: The path of the property to remove.
Returns
The modified object.
Examples
TypeScript
unset({ a: 1, b: 2 }, 'a') //=> { b: 2 } unset({ a: 1, b: 2 }, 'c') //=> { a: 1, b: 2 } (Non-existent path) // Sparse array behavior unset([1, 2, 3], '1') //=> [1, <1 empty item>, 3] const nestedObj = { x: { y: { z: ['a', null, 'b'] } } }; unset(nestedObj, 'x.y.z') //=> { x: { y: {} } }