at.js 937 B

1234567891011121314151617181920212223242526272829
  1. var baseAt = require('../internal/baseAt'),
  2. baseFlatten = require('../internal/baseFlatten'),
  3. restParam = require('../function/restParam');
  4. /**
  5. * Creates an array of elements corresponding to the given keys, or indexes,
  6. * of `collection`. Keys may be specified as individual arguments or as arrays
  7. * of keys.
  8. *
  9. * @static
  10. * @memberOf _
  11. * @category Collection
  12. * @param {Array|Object|string} collection The collection to iterate over.
  13. * @param {...(number|number[]|string|string[])} [props] The property names
  14. * or indexes of elements to pick, specified individually or in arrays.
  15. * @returns {Array} Returns the new array of picked elements.
  16. * @example
  17. *
  18. * _.at(['a', 'b', 'c'], [0, 2]);
  19. * // => ['a', 'c']
  20. *
  21. * _.at(['barney', 'fred', 'pebbles'], 0, 2);
  22. * // => ['barney', 'pebbles']
  23. */
  24. var at = restParam(function(collection, props) {
  25. return baseAt(collection, baseFlatten(props));
  26. });
  27. module.exports = at;