_baseUnset.js 580 B

123456789101112131415161718192021
  1. var castPath = require('./_castPath'),
  2. last = require('./last'),
  3. parent = require('./_parent'),
  4. toKey = require('./_toKey');
  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. module.exports = baseUnset;