_dissoc.js 699 B

123456789101112131415161718192021222324252627282930
  1. import _isInteger from "./_isInteger.js";
  2. import _isArray from "./_isArray.js";
  3. import remove from "../remove.js";
  4. /**
  5. * Returns a new object that does not contain a `prop` property.
  6. *
  7. * @private
  8. * @param {String|Number} prop The name of the property to dissociate
  9. * @param {Object|Array} obj The object to clone
  10. * @return {Object} A new object equivalent to the original but without the specified property
  11. */
  12. export default function _dissoc(prop, obj) {
  13. if (obj == null) {
  14. return obj;
  15. }
  16. if (_isInteger(prop) && _isArray(obj)) {
  17. return remove(prop, 1, obj);
  18. }
  19. var result = {};
  20. for (var p in obj) {
  21. result[p] = obj[p];
  22. }
  23. delete result[prop];
  24. return result;
  25. }