Returns the last element of an array. Passing n will return the last n elements of the array

返回一个数组中的最后一个元素

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

源码:

  _.last = function(array, n, guard) {
    if ((n != null) && !guard) {
      return slice.call(array, Math.max(array.length - n, 0));
    } else {
      return array[array.length - 1];
    }
  };

  

 

 

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