Categories

Nth Item

Get the item at a specific index using lodash _.nth

Return the item at a specific index in the array.

Highlights:

  • Uses lodash _.nth
  • Supports negative indices (counting from the end)
  • Returns a JSON-formatted value

Example:

  • Array: ["a", "b", "c", "d"]
  • Index: -1
  • Result: "d"

Enter a JSON array

Zero-based index (negative counts from the end)

Key Facts

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

Overview

The Nth Item tool retrieves the element at a specified index from a JSON array using the lodash _.nth function. It supports both positive and negative indices, allowing you to access items from the start or end of the array and returns the value in JSON format.

When to Use

  • When you need to extract a specific element from an array by its position.
  • When working with arrays where negative indices are useful for counting from the end.
  • When you want a quick, reliable way to access array elements without writing custom code.

How It Works

  • Input a valid JSON array in the 'Array' field.
  • Specify the index (zero-based, negative for reverse counting) in the 'Index' field.
  • The tool uses lodash _.nth to fetch the item and outputs it as a JSON-formatted value.

Use Cases

Extracting the last item from a list of logs or records for quick review.
Accessing a specific element in an array of configuration settings during automation.
Simplifying data extraction in scripts where array indices are dynamically determined.

Examples

1. Retrieve Last Transaction

Background
You have an array of recent transaction amounts and need the most recent one for a summary.
Problem
Manually counting indices to find the last element is error-prone and time-consuming.
How to Use
Enter the transaction array, e.g., [50, 75, 100, 125], and set the index to -1.
Outcome
The tool returns 125, the last transaction amount, as a JSON value.

2. Get Third User Input

Background
Processing a list of user-submitted answers where the third answer is critical for analysis.
Problem
Need to consistently extract the third element without manual indexing each time.
How to Use
Input the array of answers, e.g., ["yes", "no", "maybe", "unknown"], and set the index to 2.
Outcome
The third answer "maybe" is retrieved and displayed in JSON format.

Try with Samples

json

Related Hubs

FAQ

What does a negative index mean?

A negative index counts from the end of the array, where -1 is the last element.

What happens if the index is out of bounds?

The tool returns undefined for indices beyond the array length.

Can I use this with nested arrays or objects?

No, it works on a single-level array; for nested structures, use other data processing tools.

Is the index zero-based?

Yes, indices start at 0 for the first element, and negative indices count from the end.

What input format is required?

The array must be valid JSON, such as ["a", "b", "c"], and the index must be a number.

API Documentation

Request Endpoint

POST /en/api/tools/nth-item

Request Parameters

Parameter Name Type Required Description
array textarea Yes Enter a JSON array
index number No Zero-based index (negative counts from the end)

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-nth-item": {
      "name": "nth-item",
      "description": "Get the item at a specific index using lodash _.nth",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=nth-item",
      "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]