---
title: "randomItem(array) | Grafana k6 documentation"
description: "Random item from an array"
---

# randomItem(array)

Function returns a random item from an array.

Expand table

| Parameter    | Type  | Description        |
|--------------|-------|--------------------|
| arrayOfItems | array | Array \[] of items |

### Returns

Expand table

| Type | Description                |
|------|----------------------------|
| any  | Random item from the array |

### Example

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';

const names = ['John', 'Jane', 'Bert', 'Ed'];

export default function () {
  const randomName = randomItem(names);
  console.log(`Hello, my name is ${randomName}`);
}
```
