pick.js 449 B

123456789101112131415161718
  1. var slice = require('../array/slice');
  2. /**
  3. * Return a copy of the object, filtered to only have values for the whitelisted keys.
  4. */
  5. function pick(obj, var_keys){
  6. var keys = typeof arguments[1] !== 'string'? arguments[1] : slice(arguments, 1),
  7. out = {},
  8. i = 0, key;
  9. while (key = keys[i++]) {
  10. out[key] = obj[key];
  11. }
  12. return out;
  13. }
  14. module.exports = pick;