Categories

Drop Right Items

Drop last N items from array using lodash _.dropRight

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

Input: [1, 2, 3, 4, 5]
n: 2
Output: [1, 2, 3]

Example 2: Drop last 1 item (default)

Input: ['a', 'b', 'c', 'd']
n: 1
Output: ['a', 'b', 'c']

Example 3: Drop 0 items

Input: [10, 20, 30, 40]
n: 0
Output: [10, 20, 30, 40]

Example 4: Drop more than array length

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)

Enter a valid JSON array

How many items to drop from the end of the array

Key Facts

Category
Data Processing
Input Types
textarea, number
Output Type
text
Sample Coverage
4
API Ready
Yes

Overview

The Drop Right Items tool uses lodash's _.dropRight method to remove a specified number of elements from the end of an array. It provides a quick and reliable way to truncate arrays while preserving data types and structure.

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.

Examples

1. Trim Sales Data Array

Business Analyst
Background
An array contains daily sales figures, but the last two days are incomplete and should be excluded from the report.
Problem
The array has extra elements that skew the analysis.
How to Use
Enter the array [1500, 2000, 1800, 2200, 1900] and set n to 2.
Example Config
Array: [1500, 2000, 1800, 2200, 1900], n: 2
Outcome
The tool returns [1500, 2000, 1800], removing the last two sales figures.

2. Remove Last Error Message

Developer
Background
During debugging, an array of error logs has a final entry that is a system-generated placeholder.
Problem
The array includes an irrelevant last element.
How to Use
Input the array ['Syntax error', 'Null pointer', 'Timeout', 'Debug info'] and use n=1.
Example Config
Array: ['Syntax error', 'Null pointer', 'Timeout', 'Debug info'], n: 1
Outcome
The output is ['Syntax error', 'Null pointer', 'Timeout'], with the last item dropped.

Try with Samples

json, video

Related Hubs

FAQ

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.

API Documentation

Request Endpoint

POST /en/api/tools/drop-right-items

Request Parameters

Parameter Name Type Required Description
array textarea Yes Enter a valid JSON array
n number No How many items to drop from the end of the array

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-drop-right-items": {
      "name": "drop-right-items",
      "description": "Drop last N items from array using lodash _.dropRight",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=drop-right-items",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]