Removes the property of the given object at the given path.
✅
Immutable: This does not mutate the original object.
💡
If an array value is removed, then it will not return a sparsed (opens in a new tab) array.
Related
Syntax
import { toUnset } from '@opentf/std';
toUnset<T>(
obj: T,
path: string | unknown[],
): T
Examples
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: {} } }