@eroyeroy/utils - v0.1.0
    Preparing search index...

    Function uniqueBy

    • Returns a new array with duplicates removed based on the value of key. The first item for each key value is kept.

      Type Parameters

      • T
      • K extends string | number | symbol

      Parameters

      • array: readonly T[]

        The source array.

      • key: K

        The key to deduplicate by.

      Returns T[]

      uniqueBy([{ id: 1, v: "a" }, { id: 1, v: "b" }, { id: 2, v: "c" }], "id")
      // => [{ id: 1, v: "a" }, { id: 2, v: "c" }]