Removes the property of the given object at the given path.
⚠️
This mutates the original object.
Related
Syntax
import { unset } from '@opentf/std';
unset<T>(
obj: T,
path: string | unknown[],
): T
Examples
unset({ a: 1, b: 2 }, 'a') //=> { b: 2 }
unset({ a: 1, b: 2 }, 'b') //=> { a: 1 }
unset({ a: 1, b: 2 }, 'c') //=> { a: 1, b: 2 }
unset([1, 2, 3], '0') //=> [<1 Empty>, 2, 3]
unset([1, 2, 3], '1') //=> [1, <1 Empty>, 3]
unset([1, 2, 3], '2') //=> [1, 2, <1 Empty>]
unset([1, 2, 3], '3') //=> [1, 2, 3]
const nestedObj = { x: { y: { z: ['a', null, 'b'] } } };
unset(nestedObj, 'x.y.z') //=> { x: { y: {} } }