matician - v2.0.0
    Preparing search index...

    Function sumBy

    • Sums the values of a specified numeric 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 summed.

      Returns number

      The total sum of the values for the specified key.

      const data = [{ a: 2 }, { a: 3 }, { a: 5 }];
      sumBy(data, 'a'); // Returns 10