unset.js 804 B

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