first.js 384 B

12345678910111213141516171819202122
  1. /**
  2. * Gets the first element of `array`.
  3. *
  4. * @static
  5. * @memberOf _
  6. * @alias head
  7. * @category Array
  8. * @param {Array} array The array to query.
  9. * @returns {*} Returns the first element of `array`.
  10. * @example
  11. *
  12. * _.first([1, 2, 3]);
  13. * // => 1
  14. *
  15. * _.first([]);
  16. * // => undefined
  17. */
  18. function first(array) {
  19. return array ? array[0] : undefined;
  20. }
  21. module.exports = first;