Categories

Last Item

Get the last item from an array using lodash _.last

Return the final element of a JSON array.

Highlights:

  • Uses lodash _.last
  • Works with any data type
  • Returns a JSON-formatted value

Example:

  • Array: ["a", "b", "c"]
  • Result: "c"

Enter a JSON array

Key Facts

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

Overview

The Last Item tool extracts the final element from a JSON array using the lodash _.last function. It provides a quick and reliable way to retrieve the tail end of any array, supporting all data types and returning JSON-formatted output.

When to Use

  • When you need to get the last element from a list in JSON data without manual indexing.
  • When processing arrays in data workflows where the array length is dynamic or unknown.
  • When simplifying array operations in scripts or applications to avoid off-by-one errors.

How It Works

  • Input a valid JSON array into the textarea field provided.
  • The tool applies the lodash _.last function to the array.
  • It returns the last element as a JSON-formatted value for immediate use.

Use Cases

Extracting the most recent entry from a time-series data array in analytics.
Retrieving the last element in a list for pagination or navigation in web applications.
Simplifying data processing by accessing the tail of arrays in JSON-based workflows.

Examples

1. Extract Last Sales Figure

Data Analyst
Background
A data analyst has a JSON array of daily sales figures and needs to find the latest value for reporting.
Problem
Manually counting array indices is inefficient and prone to errors with large datasets.
How to Use
Enter the sales array, such as [1500, 2000, 1800, 2200], into the input field.
Outcome
The tool returns 2200, the last element, ready for use in dashboards or reports.

2. Get Last User ID from API Response

Web Developer
Background
A web developer receives a JSON array of user IDs from an API and needs to access the last one for a feature.
Problem
The array length varies, making it hard to hardcode indices without risking errors.
How to Use
Paste the array from the API response, like [101, 102, 103, 104], into the tool.
Outcome
The output is 104, allowing seamless integration into the application logic.

Try with Samples

json

Related Hubs

FAQ

What does this tool do?

It returns the last item from a JSON array using the lodash _.last function.

How do I use it?

Paste your JSON array into the input field, and the tool will output the last element instantly.

What data types are supported?

It works with any data type in the array, such as strings, numbers, objects, or nested arrays.

Is there a limit on array size?

No, it can handle arrays of any length, from small lists to large datasets.

What happens if the array is empty?

It returns undefined, as there is no last element to extract.

API Documentation

Request Endpoint

POST /en/api/tools/last-item

Request Parameters

Parameter Name Type Required Description
array textarea Yes Enter a JSON 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-last-item": {
      "name": "last-item",
      "description": "Get the last item from an array using lodash _.last",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=last-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]