or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-array-union

Create an array of unique values, in order, from the input arrays

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/array-union@3.0.x

To install, run

npx @tessl/cli install tessl/npm-array-union@3.0.0

index.mddocs/

Array Union

Array Union creates an array of unique values, in order, from the input arrays. It provides a simple, efficient utility function that flattens multiple arrays and removes duplicates while preserving the order of first occurrence.

Package Information

  • Package Name: array-union
  • Package Type: npm
  • Language: JavaScript (ES modules) with TypeScript definitions
  • Installation: npm install array-union

Core Imports

ES modules (recommended for modern environments):

import arrayUnion from "array-union";

TypeScript:

import arrayUnion from "array-union";
// or
import arrayUnion = require("array-union");

CommonJS:

const arrayUnion = require("array-union");

Basic Usage

import arrayUnion from "array-union";

// Basic array union
arrayUnion([1, 1, 2, 3], [2, 3]);
//=> [1, 2, 3]

// Single array deduplication
arrayUnion(['foo', 'foo', 'bar']);
//=> ['foo', 'bar']

// Multiple arrays with different types
arrayUnion(['🐱', 'πŸ¦„', '🐻'], ['πŸ¦„', '🌈']);
//=> ['🐱', 'πŸ¦„', '🐻', '🌈']

// Complex example with multiple arrays
arrayUnion(['🐱', 'πŸ¦„'], ['🐻', 'πŸ¦„'], ['🐢', '🌈', '🌈']);
//=> ['🐱', 'πŸ¦„', '🐻', '🐢', '🌈']

Capabilities

Array Union Function

Creates an array of unique values from any number of input arrays, preserving order of first occurrence.

/**
 * Create an array of unique values, in order, from the input arrays
 * @param arguments - Any number of arrays to union
 * @returns Array containing unique values from all input arrays
 */
function arrayUnion<ArgumentsType extends readonly unknown[]>(
  ...arguments: readonly ArgumentsType[]
): ArgumentsType;

Parameters:

  • ...arguments: Rest parameter accepting any number of arrays. Can be mixed types (numbers, strings, objects, etc.)

Returns:

  • Array containing unique values from all input arrays, maintaining the order of first occurrence
  • Return type matches the input array type through TypeScript generics

Behavior:

  • Flattens all input arrays into a single array
  • Removes duplicate values using Set-based deduplication
  • Preserves the order of first occurrence for each unique value
  • Works with any data types (primitives, objects, arrays, etc.)
  • Can be called with no arguments (returns empty array)
  • Can be called with a single array (removes duplicates from that array)

Import Notes:

  • Package uses ES modules ("type": "module" in package.json)
  • TypeScript definitions support both ES module and CommonJS import patterns
  • Default export is the arrayUnion function

Usage Examples:

// Numbers
arrayUnion([1, 2, 2, 3, 1, 2, 4], [1, 2, 3, 6, 7]);
//=> [1, 2, 3, 4, 6, 7]

// Mixed types
arrayUnion([1, 2, 2, 3, 1, 2, 4], ['c', 'a', 'd']);
//=> [1, 2, 3, 4, 'c', 'a', 'd']

// Strings only
arrayUnion(['a', 'a', 'b', 'a'], ['c', 'a', 'd']);
//=> ['a', 'b', 'c', 'd']

// Empty input
arrayUnion();
//=> []

// Single array deduplication
arrayUnion([1, 1, 2, 2, 3]);
//=> [1, 2, 3]