Remove duplicates from an array
Deduplicate primitives with a Set, or objects by a key or computed value, keeping the first occurrence.
Loading snippets…
9 snippets
Deduplicate primitives with a Set, or objects by a key or computed value, keeping the first occurrence.
Sort objects by one field, then break ties with another, with ascending or descending order per field.
Encode "at least one element" in the type so head, max and similar functions never see an empty array.
Turn a flat list of associative arrays into groups keyed by a field or callback.
Group an array into a Record by a property or function while keeping the item type.
Flatten arrays to any depth with a small recursive helper that mirrors Array.prototype.flat.
Copy selected keys from an object (or drop some) with return types that match at compile time.
Build an object of arrays keyed by a property or computed value, using Object.groupBy or a reduce fallback.
Break an array into fixed-size pieces, useful for batching API calls or database inserts.