Menu

This is documentation for the next version of K6. For the latest stable release, go to the latest version.

Open source

randomItem(array)

Function returns a random item from an array.

ParameterTypeDescription
arrayOfItemsarrayArray [] of items

Returns

TypeDescription
anyRandom item from the array

Example

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}`);
}