Aerostack
bar_chart

data-dedupe-array Edge Function — Data

Data

Removes duplicate items from an array using strict equality for primitives, deep equality for objects, or a key field for object arrays.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function data-dedupe-array Removes duplicate items from an array using strict equality for primitives, deep equality for objects, or a key field for object arrays.. 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-dedupe-array
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-dedupe-array",
  args: {
    "items": null,
    "key": "example_key"
  }
})

data-dedupe-array — Remove duplicate items from an array

Deduplicates arrays using strict equality for primitives, deep equality for objects, or a key field for efficient object deduplication.


API

POST /api/data-dedupe-array

Request body

Field Type Required Default Description
items unknown[] Array to deduplicate
key string Field name to dedupe objects by (e.g. "id")

Success response (200)

{
  "success": true,
  "data": {
    "items": [1, 2, 3],
    "removedCount": 2
  }
}

Error responses

Code HTTP When
INVALID_INPUT 400 items is not an array
INTERNAL_ERROR 500 key provided but items contain non-objects

Usage

cURL
curl -X POST "$FUNCTION_URL" \
  -H "Content-Type: application/json" \
  -d '{"items": [{"id":1},{"id":2},{"id":1}], "key": "id"}'
TypeScript / JavaScript (HTTP)
const response = await fetch(FUNCTION_URL, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ items: users, key: 'email' }),
});
const { data } = await response.json();
console.log(data.items, `removed: ${data.removedCount}`);
Direct import (Node / Bun / Deno)
import { dedupeArray } from '@aerostack/functions/data-dedupe-array';

const { items, removedCount } = dedupeArray({ items: userList, key: 'userId' });

Use Cases

  • Deduplicating user records merged from multiple data sources before database import
  • Removing duplicate tag or category values from user-generated content
  • Ensuring uniqueness of items in a workflow pipeline before passing to a downstream step

Notes

  • First occurrence is always kept; subsequent duplicates are removed
  • For objects without key: uses JSON.stringify deep equality — key order matters
  • For primitives: uses strict value equality via JSON.stringify

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-dedupe-array function do? +

data-dedupe-array 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-dedupe-array function? +

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

What runtime does data-dedupe-array use? +

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

Can I customise the data-dedupe-array function? +

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