Pair with initial/rest._.initial drops the last; _.rest drops the first.
Pick by intent. Use the helper that names the end you care about.
Compatibility
Browser & Runtime Support
_.last ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.
✓ Stable · Underscore 1.x
_.last()
Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.
100%With Underscore 1.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.lastUnderscore 1.x+
Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).
Frequently Asked Questions
_.last(array) returns the last element. Passing n as _.last(array, n) returns the last n elements as a new array. Official example: _.last([5, 4, 3, 2, 1]) → 1.
Without n, _.last([]) returns undefined. With n, such as _.last([], 2), it returns [].
Yes. _.last([5, 4, 3, 2, 1], 2) is [2, 1] — original order, not reversed.
For one element they match on a non-empty array. _.last also supports n trailing elements and returns undefined for an empty array without computing a bad index.
_.first takes from the start; _.last takes from the end. Both accept an optional count.
No. It returns an element or a new array; the source is unchanged.