randomItem(array)
函数返回数组中的一个随机项。
参数 | 类型 | 描述 |
---|---|---|
arrayOfItems | 数组 | 项的数组 [] |
返回值
类型 | 描述 |
---|---|
任意类型 | 数组中的随机项 |
示例
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}`);
}