matician - v2.0.0
    Preparing search index...

    Function productBy

    • Calculates the product of all numeric values 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 multiplied.

      Returns number

      The product of values, or 1 if no valid numbers are found.

      const data = [{ a: 2 }, { a: 3 }, { a: 4 }];
      productBy(data, 'a'); // Returns 24