pick.js 629 B

1234567891011121314151617181920212223242526
  1. var basePick = require('./_basePick'),
  2. flatRest = require('./_flatRest');
  3. /**
  4. * Creates an object composed of the picked `object` properties.
  5. *
  6. * @static
  7. * @since 0.1.0
  8. * @memberOf _
  9. * @category Object
  10. * @param {Object} object The source object.
  11. * @param {...(string|string[])} [paths] The property paths to pick.
  12. * @returns {Object} Returns the new object.
  13. * @example
  14. *
  15. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  16. *
  17. * _.pick(object, ['a', 'c']);
  18. * // => { 'a': 1, 'c': 3 }
  19. */
  20. var pick = flatRest(function(object, paths) {
  21. return object == null ? {} : basePick(object, paths);
  22. });
  23. module.exports = pick;