_baseUnset.js 578 B

1234567891011121314151617181920
  1. import castPath from './_castPath.js';
  2. import last from './last.js';
  3. import parent from './_parent.js';
  4. import toKey from './_toKey.js';
  5. /**
  6. * The base implementation of `_.unset`.
  7. *
  8. * @private
  9. * @param {Object} object The object to modify.
  10. * @param {Array|string} path The property path to unset.
  11. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  12. */
  13. function baseUnset(object, path) {
  14. path = castPath(path, object);
  15. object = parent(object, path);
  16. return object == null || delete object[toKey(last(path))];
  17. }
  18. export default baseUnset;