import { uniqueBy } from "https://deno.land/x/ayonli_jsext@v0.9.72/array/index.ts";
Returns a subset of the array that contains only unique items filtered by the given callback function.
Examples
Example 1
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" }
// ]