Filters out duplicated values based on the result of the given key selector.

Type signature

(f: (x: any) => any) => (xs: any[]) => any[]

Examples

uniqueBy(({ id }) => id)([
  { id: 1, value: "a" },
  { id: 2, value: "b" },
  { id: 1, value: "c" },
]);
// ⇒ [{ id: 1, value: 'c' }, { id: 2, value: 'b' }]
Try in REPL

Questions

  • How to find all unique values in an array by some predicate?

TypeScript sourceJavaScript source