Array Utilities

Array Interleave

Array Interleave merges two arrays by alternating their elements into a single array. Use via MCP in Cursor or Windsurf, or call GET /v1/array/interleave with array1 and array2 parameters. Example: [1,2,3] + [a,b,c] becomes [1,a,2,b,3,c]. Handles arrays of different lengths by appending remaining elements.

API Endpoint

GET /v1/array/interleave

Code Examples

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

The function alternates elements until the shorter array is exhausted, then appends all remaining elements from the longer array to the result.

Can I interleave arrays with different data types?

Yes, you can interleave arrays containing strings, numbers, booleans, or mixed types. The output preserves the original data types of each element.

What's the difference between array interleaving and concatenation?

Concatenation joins arrays end-to-end ([1,2] + [3,4] = [1,2,3,4]), while interleaving alternates elements ([1,2] + [3,4] = [1,3,2,4]).

How do I use array interleave in my MCP-enabled AI coding assistant?

Ask your AI assistant to interleave two arrays, and it will call the TinyFn tool automatically. Works in Cursor, Claude Code, and other MCP-supported editors.

What happens when I interleave empty arrays?

Interleaving with an empty array returns the non-empty array unchanged. Interleaving two empty arrays returns an empty array.

Try Array Interleave Now

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

Get Free API Key