UNPKG

804 BJavaScriptView Raw
1var baseUnset = require('./_baseUnset');
2
3/**
4 * Removes the property at `path` of `object`.
5 *
6 * **Note:** This method mutates `object`.
7 *
8 * @static
9 * @memberOf _
10 * @since 4.0.0
11 * @category Object
12 * @param {Object} object The object to modify.
13 * @param {Array|string} path The path of the property to unset.
14 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
15 * @example
16 *
17 * var object = { 'a': [{ 'b': { 'c': 7 } }] };
18 * _.unset(object, 'a[0].b.c');
19 * // => true
20 *
21 * console.log(object);
22 * // => { 'a': [{ 'b': {} }] };
23 *
24 * _.unset(object, ['a', '0', 'b', 'c']);
25 * // => true
26 *
27 * console.log(object);
28 * // => { 'a': [{ 'b': {} }] };
29 */
30function unset(object, path) {
31 return object == null ? true : baseUnset(object, path);
32}
33
34module.exports = unset;