Aerostack
bar_chart

data-array-group-by Edge Function — Data

Data

Groups an array of objects into a map keyed by the value of a specified property. Zero dependencies.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function data-array-group-by Groups an array of objects into a map keyed by the value of a specified property. Zero dependencies.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.

terminal — aerostack cli
$ npx aerostack add navin/data-array-group-by
smart_toy

Use with AI Assistants

MCP

Connect Claude, Cursor, or any MCP-compatible client — then call this function by slug

① Add MCP Server

Add this once — access all Aerostack functions from your AI tool.

claude_desktop_config.json
{
  "mcpServers": {
    "aerostack": {
      "url": "https://mcp.aerostack.dev",
      "type": "http"
    }
  }
}

② Call this function

Ask your AI to use the call_function tool with this slug:

call_function
call_function({
  slug: "data-array-group-by",
  args: {
    "array": null,
    "key": "example_key"
  }
})

data-array-group-by

Groups an array of objects into a map keyed by the value of a specified property. Zero external dependencies.

Install

aerostack function add data-array-group-by

Usage

import { groupBy } from './functions/data-array-group-by';

const users = [
    { name: 'Alice', role: 'admin' },
    { name: 'Bob', role: 'user' },
    { name: 'Charlie', role: 'admin' },
];

groupBy(users, 'role');
// {
//   groups: {
//     admin: [{ name: 'Alice', role: 'admin' }, { name: 'Charlie', role: 'admin' }],
//     user:  [{ name: 'Bob', role: 'user' }]
//   }
// }

API

POST /api/data-array-group-by
{
    "array": [
        { "name": "Alice", "role": "admin" },
        { "name": "Bob", "role": "user" },
        { "name": "Charlie", "role": "admin" }
    ],
    "key": "role"
}
{
    "success": true,
    "data": {
        "groups": {
            "admin": [
                { "name": "Alice", "role": "admin" },
                { "name": "Charlie", "role": "admin" }
            ],
            "user": [
                { "name": "Bob", "role": "user" }
            ]
        }
    }
}
Field Type Required Description
array array Yes Array of objects to group
key string Yes Property name to group by

Edge Cases

  • Missing key in some objects: grouped under "undefined"
  • null values: grouped under "undefined"
  • Number/boolean values: converted to string keys (5 becomes "5", true becomes "true")
  • Empty array: returns error EMPTY_ARRAY
  • Empty key string: returns error MISSING_KEY

Metadata

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

data
deployed_code

Build and publish your own functions

Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.

More Data Functions

Browse Data Functions →

Frequently asked questions

What does the data-array-group-by function do? +

data-array-group-by is a serverless edge function for data automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.

How do I deploy the data-array-group-by function? +

Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/data-array-group-by ``` It will be live on Cloudflare Workers in seconds.

What runtime does data-array-group-by use? +

data-array-group-by runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.

Can I customise the data-array-group-by function? +

Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.