pickByArray.js 611 B

12345678910111213141516171819202122232425262728
  1. var toObject = require('./toObject');
  2. /**
  3. * A specialized version of `_.pick` which picks `object` properties specified
  4. * by `props`.
  5. *
  6. * @private
  7. * @param {Object} object The source object.
  8. * @param {string[]} props The property names to pick.
  9. * @returns {Object} Returns the new object.
  10. */
  11. function pickByArray(object, props) {
  12. object = toObject(object);
  13. var index = -1,
  14. length = props.length,
  15. result = {};
  16. while (++index < length) {
  17. var key = props[index];
  18. if (key in object) {
  19. result[key] = object[key];
  20. }
  21. }
  22. return result;
  23. }
  24. module.exports = pickByArray;