Array Utilities

Array Nth

Extracts the element at a specified index from any array. Use `/v1/array/nth` with your array and index parameter, supporting negative indices for reverse access. Returns the exact value at that position or null for out-of-bounds indices. Perfect for MCP-enabled editors like Cursor when processing dynamic arrays.

API Endpoint

GET /v1/array/nth

Code Examples

curl "https://tinyfn.io/v1/array/nth" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/array/nth', {
  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/nth',
    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 negative indices work with array nth?

Negative indices count backwards from the end: -1 gets the last element, -2 gets second-to-last, etc. Out-of-bounds negative indices return null.

What happens when I request an index that doesn't exist?

Returns null for any out-of-bounds index, whether positive or negative. No errors thrown, making it safe for dynamic array processing.

Can I use array nth with nested arrays or objects?

Yes, it returns whatever type exists at that index - strings, numbers, objects, or nested arrays. The tool preserves the original data type.

How does array nth compare to direct bracket notation in code?

Provides the same functionality but through MCP, letting AI agents access array elements without executing arbitrary code. Useful for data analysis workflows.

Does array nth work with empty arrays?

Yes, but any index request on an empty array returns null since no valid indices exist.

Try Array Nth Now

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

Get Free API Key