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

    Function maxBy

    • Returns the item with the maximum value of key, or undefined for an empty array. Items where the key value is null or undefined are skipped.

      Type Parameters

      • T
      • K extends string | number | symbol

      Parameters

      • array: readonly T[]

        The array to search.

      • key: K

        The key to compare (string, number, or Date).

      Returns T | undefined

      maxBy([{ age: 25 }, { age: 30 }, { age: 20 }], "age") // => { age: 30 }
      maxBy([], "age") // => undefined