Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/esm/array.js>uniqueBy

A JavaScript extension package for building strong and modern applications.
Latest
function uniqueBy
import { uniqueBy } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/array.js";

Returns a subset of the array that contains only unique items filtered by the given callback function.

Examples

Example 1

import { uniqueBy } from "@ayonli/jsext/array";

const arr = [
    { id: 1, name: "foo" },
    { id: 2, name: "bar" },
    { id: 3, name: "foo" },
    { id: 4, name: "baz" },
    { id: 5, name: "bar" },
];

console.log(uniqueBy(arr, item => item.name));
// [
//     { id: 1, name: "foo" },
//     { id: 2, name: "bar" },
//     { id: 4, name: "baz" }
// ]