Removes the property of the given object at the given path.
Info
Immutable: This does not mutate the original object.
Note
If an array value is removed, then it will not return a sparsed array.
Related
Syntax
TypeScript
import { toUnset } from '@opentf/std'; toUnset<T>( obj: T, path: string | unknown[], ): T
Examples
TypeScript
const obj = { a: 1, b: 2 }; toUnset(obj, 'a') //=> { b: 2 } toUnset(obj, 'b') //=> { a: 1 } toUnset(obj, 'c') //=> { a: 1, b: 2 } const arr = [1, 2, 3]; toUnset(arr, '0') //=> [2, 3] toUnset(arr, '1') //=> [1, 3] toUnset(arr, '3') //=> [1, 2, 3] const nestedObj = { x: { y: { z: ['a', null, 'b'] } } }; toUnset(nestedObj, 'x.y.z') //=> { x: { y: {} } }