# Drop Right Items

Drop last N items from array using lodash _.dropRight

> Canonical page: https://elysiatools.com/en/tools/drop-right-items

- **Category:** Data Processing

- **Keywords:** array, drop, right, remove, slice, truncate, lodash

## Overview

## Drop Right Items

This tool removes a specified number of elements from the **end** of an array using lodash's `_.dropRight` method.

### Features
- **Remove from end**: Drop elements from the right side of the array
- **Flexible input**: Accept any valid JSON array
- **Configurable**: Specify how many items to drop
- **Type preservation**: Maintains array structure and data types

### Examples

**Example 1: Drop last 2 items**
```json
Input: [1, 2, 3, 4, 5]
n: 2
Output: [1, 2, 3]
```

**Example 2: Drop last 1 item (default)**
```json
Input: ['a', 'b', 'c', 'd']
n: 1
Output: ['a', 'b', 'c']
```

**Example 3: Drop 0 items**
```json
Input: [10, 20, 30, 40]
n: 0
Output: [10, 20, 30, 40]
```

**Example 4: Drop more than array length**
```json
Input: [1, 2, 3]
n: 10
Output: []
```

### Notes
- If `n` is greater than array length, returns empty array `[]`
- If `n` is 0, returns a copy of the original array
- Input must be valid JSON array string
- Works with arrays of any type (numbers, strings, objects, nested arrays)

## Inputs

- **Array** (textarea): Enter a valid JSON array
- **Number of Items to Drop** (number): How many items to drop from the end of the array

## When to use

- When you need to trim trailing elements from an array for data cleaning.
- To remove the last few items in a list during data preprocessing.
- For array manipulation in scripts or workflows where end elements are unnecessary.

## How it works

- Input a valid JSON array into the designated field.
- Optionally specify the number of items to drop from the end using the n parameter.
- The tool processes the input and returns a new array with the last n items removed.
- Handles edge cases: if n is 0, returns a copy; if n exceeds length, returns an empty array.

## Use cases

- Cleaning up test data by removing placeholder elements at the end of an array.
- Trimming historical data to exclude the most recent entries for analysis.
- Preparing array data for APIs or exports by dropping unnecessary trailing items.

## Frequently asked questions

### What is the default number of items dropped?

The default is 1, meaning it drops the last item by default.

### Can I drop zero items?

Yes, setting n to 0 returns a copy of the original array without any changes.

### What happens if I try to drop more items than the array has?

If n is greater than the array length, the tool returns an empty array.

### Does this tool modify the original array?

No, it returns a new array; the input array remains unchanged.

### What types of arrays are supported?

It supports any valid JSON array, including numbers, strings, objects, and nested arrays.

## Related tools

- [Compact Array](https://elysiatools.com/en/tools/compact-array): Remove falsey values from array using lodash _.compact
- [Drop Items](https://elysiatools.com/en/tools/drop-items): Drop first N items from array using lodash _.drop
- [Pull Values](https://elysiatools.com/en/tools/pull-values): Remove specific values from an array using lodash _.pull
- [Sorted Unique](https://elysiatools.com/en/tools/sorted-unique): Remove duplicates from a sorted array using lodash _.sortedUniq
- [Sorted Unique By](https://elysiatools.com/en/tools/sorted-unique-by): Remove duplicates from a sorted array using lodash _.sortedUniqBy
- [Uniq Array](https://elysiatools.com/en/tools/uniq-array): Remove duplicates from an array using lodash _.uniq
- [Uniq By](https://elysiatools.com/en/tools/uniq-by): Remove duplicates from an array using lodash _.uniqBy with a property path
- [Without Values](https://elysiatools.com/en/tools/without-values): Remove specified values from an array using lodash _.without

## Samples

- [Grafana Advanced Application Samples](https://elysiatools.com/en/samples/grafana-samples): Comprehensive Grafana samples covering advanced dashboard design, alerting configurations, data source integrations, and plugin development
- [QR Code Samples](https://elysiatools.com/en/samples/qrcode-samples): Sample QR code images for testing QR code reading and generation tools
- [D3.js Data Visualization Samples](https://elysiatools.com/en/samples/d3js-data-visualization): Comprehensive D3.js data visualization examples including charts, maps, animations, and interactive visualizations
- [Rome JavaScript Toolchain Samples](https://elysiatools.com/en/samples/rome): Rome JavaScript toolchain examples including configuration, linting, formatting, bundling, and project management
