arrayAvg

Calculates the average of the values in an array.
All elements in the array must contain values that can be
automatically converted to numeric.

arrayAvg(array) → returns Numeric

Member Function Syntax

someArray.avg()

Argument Reference for the arrayAvg function

array

Required: Yes
An array which to determine average

Examples sample code invoking the arrayAvg function


Average value of an array

Uses the arrayAvg function to get average value of an array

numberArray = [1,2,3];
writeOutput(arrayAvg(numberArray));

Expected Result: 2


Average value of an array using the Array member function

CF 11+ Lucee 4.5+ Uses the avg member function is the same as running arrayAvg.

numberArray = [1,2,3];
writeOutput(numberArray.avg());

Expected Result: 2


Fork me on GitHub