matician - v2.0.0
    Preparing search index...

    Function maxBy

    • Finds the maximum numeric value of a specified property in an array of objects.

      Type Parameters

      • T extends Record<string, any>

        The type of objects in the array.

      Parameters

      • items: T[]

        The array of objects.

      • key: keyof T

        The key whose numeric values will be compared.

      Returns number

      The maximum value, or -Infinity if no valid number is found.

      const data = [{ a: 5 }, { a: 2 }, { a: 9 }];
      maxBy(data, 'a'); // Returns 9