Skip to main content
The Deno 2 Release Candidate is here
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function distinct
import { distinct } from "https://deno.land/std@0.217.0/collections/distinct.ts";

Returns all distinct elements in the given array, preserving order by first occurrence.

Examples

Example 1

import { distinct } from "https://deno.land/std@0.217.0/collections/distinct.ts";
import { assertEquals } from "https://deno.land/std@0.217.0/assert/assert_equals.ts";

const numbers = [3, 2, 5, 2, 5];
const distinctNumbers = distinct(numbers);

assertEquals(distinctNumbers, [3, 2, 5]);

Parameters

array: Iterable<T>