Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
randomItem(array)
Function returns a random item from an array.
Parameter | Type | Description |
---|---|---|
arrayOfItems | array | Array [] of items |
Returns
Type | Description |
---|---|
any | Random item from the array |
Example
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}`);
}