> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# mean es-toolkit

Calculates the average of an array of numbers.

```typescript
const average = mean(nums);
```

## Usage

### `mean(nums)`

Use `mean` when you want to find the average value of an array of numbers. It calculates the average by adding all numbers together and dividing by the length of the array. If given an empty array, it returns `NaN`.

```typescript
import { mean } from 'es-toolkit/math';

// Calculate the average of an array of numbers
const numbers = [1, 2, 3, 4, 5];
const result = mean(numbers);
// result is 3 ((1 + 2 + 3 + 4 + 5) / 5 = 15 / 5 = 3)

// Calculate the average of decimal numbers
const decimals = [1.5, 2.5, 3.5];
const decimalResult = mean(decimals);
// decimalResult is 2.5

// Returns NaN for an empty array
const emptyResult = mean([]);
// emptyResult is NaN
```

#### Parameters


numsreadonly number[]required

An array of numbers to calculate the average.

#### Returns

Returns the average of all numbers in the array. Returns `NaN` if the array is empty.

```typescript
number
```


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/reference/math/mean.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
