Browse API packages

API · v0.19.0

array

Standard library arrays

Member signatures use schematic object.member(...) API notation. Exported type declarations are valid TypeScript.

Utilities for comparing, inspecting, and normalizing arrays.

Methods requiring array inputs validate them consistently with assert.array(). These utilities work in current browsers, Node, Deno, and Bun.

ts
import array from "@rcompat/array";

array.difference#

Returns elements from the first array that the second does not include.

Membership uses the same SameValueZero comparison as Array.includes. The input arrays are not modified.

ts
array.difference(a: unknown[], b: unknown[]): unknown[];

Example

ts
array.difference([1, 2, 2, 3], [2]); // [1, 3]

array.empty#

Returns whether an array contains no elements.

ts
array.empty(array: unknown[]): boolean;

Example

ts
array.empty([]); // true
array.empty([0]); // false

array.to#

Returns an array unchanged or wraps a non-array value in an array.

ts
array.to<T>(value: T | T[]): T[];

Example

ts
array.to("value"); // ["value"]
const values = ["value"];
array.to(values) === values; // true