> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# takeRightWhile es-toolkit

Returns a new array by taking elements from the end of the array while the condition function returns true.

```typescript
const result = takeRightWhile(arr, shouldContinueTaking);
```

## Usage

### `takeRightWhile(arr, shouldContinueTaking)`

Use `takeRightWhile` when you want to take elements from the end of an array that meet a condition. It stops when it encounters the first element for which the condition function returns false.

```typescript
import { takeRightWhile } from 'es-toolkit/array';

// Take numbers less than 4 from the end
takeRightWhile([5, 4, 3, 2, 1], n => n < 4);
// Result: [3, 2, 1]

// Take numbers greater than 3 from the end
takeRightWhile([1, 2, 3], n => n > 3);
// Result: []

// Take elements with string length <= 5
takeRightWhile(['hello', 'world', 'foo', 'bar'], str => str.length <= 5);
// Result: ['hello', 'world', 'foo', 'bar']
```

#### Parameters


arrT[]required

The array to take elements from.


shouldContinueTaking(item: T, index: number, array: T[]) => booleanrequired

A condition function called with each element, its index, and the array. Elements are included in the result as long as this function returns true.

#### Returns

A new array containing the elements taken from the end while the condition function returns true.

```typescript
T[]
```

## Examples

```typescript
// Using index parameter
takeRightWhile([10, 20, 30, 40], (x, index) => index > 1);
// Returns: [30, 40]

// Using array parameter
takeRightWhile([1, 2, 3, 4], (x, index, arr) => x >= arr.length / 2);
// Returns: [2, 3, 4]
```


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/reference/array/takeRightWhile.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
