Lodash _.takeRight() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

Creates a slice of array with n elements taken from the end. Part of Lodash Array since 3.0.0 (stable in 4.x — not deprecated).

Pass the required arguments shown below. Lodash Array helpers usually return a new value — check whether the source array is mutated.

Syntax

Call _.takeRight on an array. Start with this line.

Lodash
_.takeRight(array, [n=1])
CallWhat it does
_.takeRight(array, [n=1])Primary signature.
_.takeRight(array)Call with an array argument.

Prefer import takeRight from "lodash/takeRight" when you want a smaller bundle.

Library declarations
Lodash
_.takeRight(array, [n=1])

Parameters

ParameterDescription
arrayRequired. Source to query
nOptional. Count to take from the end; default 1

Return Value

Return ValueDescription
*New array of up to n trailing elements

Lodash Examples

Example 1 — Official: Default Take One from End

Omit n and Lodash keeps only the last element.

Lodash
_.takeRight([1, 2, 3]);
// → [3]
Try It Yourself

How It Works

  1. Source. Array [1, 2, 3]; last slot is 3.
  2. Default. Missing n means take 1 item from the end.
  3. Keep tail. Only 3 is included.
  4. New array. Result is [3] — not a bare value like _.last.

Example 2 — Official: Take a Specific Count from End

Pass n to keep several trailing values in one call.

Lodash
_.takeRight([1, 2, 3], 2);
// → [2, 3]
Try It Yourself

How It Works

  1. Ask for 2. Keep the last two slots.
  2. Start index. length - 2 = 1.
  3. Kept. 2 and 3 form the result.
  4. Same as slice. Equivalent to [1, 2, 3].slice(-2).

Example 3 — Official: n Larger Than Length

Taking more items than exist returns the whole array.

Lodash
_.takeRight([1, 2, 3], 5);
// → [1, 2, 3]
Try It Yourself

How It Works

  1. Ask for 5. Source only has 3 items.
  2. Clamp. Start index becomes 0.
  3. Result. All three values in a new array.
  4. Safe. No throw — oversized n is fine.

Example 4 — Official: Take Zero

n = 0 keeps nothing.

Lodash
_.takeRight([1, 2, 3], 0);
// → []
Try It Yourself

How It Works

  1. Count is 0. No trailing slots are requested.
  2. Empty slice. Result is [].
  3. Source safe. Original array is unchanged.
  4. Use. Handy when n comes from a variable that may be zero.

Example 5 — Empty Array

Taking from an empty source stays empty.

Lodash
_.takeRight([], 2);
// → []
Try It Yourself

How It Works

  1. Empty source. No elements to keep.
  2. Result. Lodash returns [].
  3. Safe. No throw — fine in pipelines with optional data.
  4. Guard. Check length before assuming a suffix exists.

Browser & Runtime Support

_.takeRight is a Lodash 4.x Array helper (since 3.0.0). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 3.0.0+

_.takeRight()

Available in [email protected] full builds and the lodash/takeRight modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.takeRight Lodash 3.0.0+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import takeRight from "lodash/takeRight" for smaller builds. Not a native browser API — load Lodash first.

Frequently Asked Questions

_.takeRight(array, n) creates a new array with up to n elements from the end. The default for n is 1. The source array is not mutated.
No. Lodash returns a new array (a slice of the trailing elements). The input stays unchanged.
When n is omitted, Lodash takes one element from the end — the same everyday “last item only” case as _.last, but as a one-element array.
You get every element — a shallow copy of the whole array. Nothing throws.
You get an empty array []. Nothing is taken from the end.
Use import takeRight from "lodash/takeRight" or require("lodash/takeRight") so bundlers can tree-shake. Full build: import _ from "lodash" then _.takeRight.

Next: _.takeRightWhile()

Keep a trailing run with a predicate instead of a fixed count.

_.takeRightWhile() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful