mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Add an optional index argument to _.last()
This makes _.last() behave the same as _.first(). Passing an optional second argument n will return the last n elements of the array.
This commit is contained in:
@@ -306,9 +306,10 @@
|
||||
return slice.call(array, (index == null) || guard ? 1 : index);
|
||||
};
|
||||
|
||||
// Get the last element of an array.
|
||||
_.last = function(array) {
|
||||
return array[array.length - 1];
|
||||
// Get the last element of an array. Passing **n** will return the last N
|
||||
// values in the array.
|
||||
_.last = function(array, n) {
|
||||
return (n != null) ? slice.call(array, array.length - n) : array[array.length - 1];
|
||||
};
|
||||
|
||||
// Trim out all falsy values from an array.
|
||||
|
||||
Reference in New Issue
Block a user