Array Utilities

Group By Length

Group By Length organizes array items by their string length, returning a map where keys are lengths and values are arrays of matching items. Use via MCP in Cursor or Windsurf, or call GET /v1/array/group-by-length directly. Perfect for text analysis, data categorization, or preparing datasets where string length matters for processing logic.

API Endpoint

GET /v1/array/group-by-length

Code Examples

curl "https://tinyfn.io/v1/array/group-by-length" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/array/group-by-length', {
  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/group-by-length',
    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 group by length handle mixed data types in arrays?

It converts all items to strings first, then groups by the resulting string length. Numbers, booleans, and objects get stringified before length calculation.

What format does the grouped output use?

Returns a JSON object with string length as keys and arrays of matching items as values, like {"3": ["cat", "dog"], "4": ["bird"]}.

Can I use this MCP tool for analyzing user input patterns?

Yes, it's excellent for categorizing form inputs, analyzing password lengths, or grouping search queries by character count in AI agent workflows.

Does it preserve the original order of items within each length group?

Yes, items maintain their original array order within each length group, making results predictable and consistent.

How does it handle empty strings or null values?

Empty strings group under length "0", while null/undefined values are converted to strings ("null"/"undefined") and grouped by their string representation length.

Try Group By Length Now

Get your free API key and start using Group By Length in seconds.

Get Free API Key