Array Utilities

Array Frequency

Counts how often each item appears in an array, returning frequency statistics as key-value pairs. Access via MCP in Cursor or Windsurf for AI-powered data analysis, or call GET /v1/array/frequency directly. Input `["apple", "banana", "apple"]` returns `{"apple": 2, "banana": 1}`. Handles strings, numbers, and mixed data types deterministically.

API Endpoint

GET /v1/array/frequency

Code Examples

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

Each unique value is treated as a distinct key regardless of type. Numbers and strings are separate: `[1, "1", 1]` returns `{"1": 2, "1": 1}`.

Can I use array frequency in MCP tools for data analysis?

Yes, it's available in Cursor, Claude Code, and other MCP-compatible editors. Perfect for analyzing datasets, counting categorical variables, or finding duplicate patterns in AI workflows.

What's the output format for array frequency counting?

Returns a JSON object where keys are the unique array items and values are their occurrence counts. Empty arrays return `{}`.

Does array frequency preserve the original data types in results?

Keys in the result object are always strings (JSON limitation), but the counting logic respects original types during processing.

How does array frequency handle null and undefined values?

Null values are counted as `"null"` keys. Undefined values are typically converted to `"undefined"` or filtered out depending on input parsing.

Try Array Frequency Now

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

Get Free API Key