Menu
Open source
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
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}`);
}
Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video
Performance testing and observability in Grafana Cloud
In this webinar, learn how Grafana Cloud k6 offers you the best developer experience for performance testing.
User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.