Array Utilities

Array Compact

Array Compact filters out falsy values like null, undefined, empty strings, 0, and false from arrays. Access via MCP in Cursor or Windsurf, or REST at GET /v1/array/compact. Pass ["hello", "", null, "world", 0] and get ["hello", "world"] back. Deterministic filtering ensures consistent results across AI agent workflows.

API Endpoint

GET /v1/array/compact

Code Examples

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

What values does array compact remove?

Removes all falsy values: null, undefined, false, 0, empty strings (""), and NaN. Keeps truthy values including non-empty strings, numbers > 0, objects, and arrays.

How do I use array compact in MCP tools like Cursor?

Call the array_compact function with your array parameter. The MCP tool handles the REST API call and returns the cleaned array directly in your AI workflow.

Does array compact preserve object structure in nested arrays?

Only removes falsy primitive values at the top level. Objects and nested arrays are preserved intact, even if they contain falsy properties internally.

What's the difference between array compact and filter?

Array compact specifically removes falsy values using JavaScript's truthiness rules. Filter requires custom logic and predicates for each use case.

Can I compact arrays with mixed data types?

Yes, works with any JavaScript array containing mixed primitives, objects, or arrays. Only falsy primitives are removed regardless of other element types.

Try Array Compact Now

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

Get Free API Key