Array Utilities

Array Last

Extracts the last n elements from any array with deterministic results. Call via MCP in Cursor or Windsurf, or use REST endpoint `/v1/array/last`. Perfect for getting recent items, tail operations, or pagination boundaries. Returns empty array if n exceeds array length, making it safe for dynamic data processing.

API Endpoint

GET /v1/array/last

Code Examples

curl "https://tinyfn.io/v1/array/last" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/array/last', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/array/last',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's array tools:

{
  "mcpServers": {
    "tinyfn-array": {
      "url": "https://tinyfn.io/mcp/array",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How do I get the last 3 items from an array using Array Last?

Pass your array and set n=3. For array [1,2,3,4,5], it returns [3,4,5]. Works with any data type including strings, objects, or mixed arrays.

What happens if I request more items than the array contains?

Array Last returns the entire array without errors. Requesting last 10 items from a 5-item array simply returns all 5 items in their original order.

Can MCP tools like Cursor use Array Last for processing dynamic lists?

Yes, AI agents frequently use it for analyzing recent data points, extracting tail elements for pattern recognition, or implementing sliding window operations on datasets.

Does Array Last preserve the original order of elements?

Absolutely. Elements maintain their sequential order from the source array. It's not a reverse operation—just extraction of the final n elements.

What's the difference between Array Last and array slicing?

Array Last provides a clean, parameterized interface optimized for tail operations. Unlike manual slicing, it handles edge cases automatically and works consistently across MCP and REST environments.

Try Array Last Now

Get your free API key and start using Array Last in seconds.

Get Free API Key