_.first(array, [n]) Alias: head 
Returns the first element of an array. Passing n will return the first n elements of the array

返回数组的第一个元素. 别名head

1 _.first([5, 4, 3, 2, 1]);
2 => 5

源码:

  _.first = _.head = _.take = function(array, n, guard) {
    return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
  };

 

 

posted on 2012-04-15 22:12  himanhimao  阅读(321)  评论(0编辑  收藏  举报