<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>utils on Grafana Labs</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/</link><description>Recent content in utils on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/k6/v2.3.x/javascript-api/jslib/utils/index.xml" rel="self" type="application/rss+xml"/><item><title>randomIntBetween(min, max)</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/randomintbetween/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/randomintbetween/</guid><content><![CDATA[&lt;h1 id=&#34;randomintbetweenmin-max&#34;&gt;randomIntBetween(min, max)&lt;/h1&gt;
&lt;p&gt;Function returns a random number between the specified range. The returned value is no lower than (and may possibly equal) min, and is no bigger than (and may possibly equal) max.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;min&lt;/td&gt;
              &lt;td&gt;int&lt;/td&gt;
              &lt;td&gt;Lower-end bound. Inclusive&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;max&lt;/td&gt;
              &lt;td&gt;int&lt;/td&gt;
              &lt;td&gt;Upper-end bound. Inclusive&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;int&lt;/td&gt;
              &lt;td&gt;Random integer&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { sleep } from &amp;#39;k6&amp;#39;;
import { randomIntBetween } from &amp;#39;https://jslib.k6.io/k6-utils/1.2.0/index.js&amp;#39;;

export default function () {
  // code ...

  sleep(randomIntBetween(1, 5)); // sleep between 1 and 5 seconds.
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="randomintbetweenmin-max">randomIntBetween(min, max)&lt;/h1>
&lt;p>Function returns a random number between the specified range. The returned value is no lower than (and may possibly equal) min, and is no bigger than (and may possibly equal) max.&lt;/p></description></item><item><title>randomItem(array)</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/randomitem/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/randomitem/</guid><content><![CDATA[&lt;h1 id=&#34;randomitemarray&#34;&gt;randomItem(array)&lt;/h1&gt;
&lt;p&gt;Function returns a random item from an array.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;arrayOfItems&lt;/td&gt;
              &lt;td&gt;array&lt;/td&gt;
              &lt;td&gt;Array [] of items&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;any&lt;/td&gt;
              &lt;td&gt;Random item from the array&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { randomItem } from &amp;#39;https://jslib.k6.io/k6-utils/1.2.0/index.js&amp;#39;;

const names = [&amp;#39;John&amp;#39;, &amp;#39;Jane&amp;#39;, &amp;#39;Bert&amp;#39;, &amp;#39;Ed&amp;#39;];

export default function () {
  const randomName = randomItem(names);
  console.log(`Hello, my name is ${randomName}`);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="randomitemarray">randomItem(array)&lt;/h1>
&lt;p>Function returns a random item from an array.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Parameter&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>arrayOfItems&lt;/td>
&lt;td>array&lt;/td>
&lt;td>Array [] of items&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="returns">Returns&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>any&lt;/td>
&lt;td>Random item from the array&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="example">Example&lt;/h3>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import { randomItem } from &amp;#39;https://jslib.k6.io/k6-utils/1.2.0/index.js&amp;#39;;
const names = [&amp;#39;John&amp;#39;, &amp;#39;Jane&amp;#39;, &amp;#39;Bert&amp;#39;, &amp;#39;Ed&amp;#39;];
export default function () {
const randomName = randomItem(names);
console.log(`Hello, my name is ${randomName}`);
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div></description></item><item><title>randomString(length, [charset])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/randomstring/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/randomstring/</guid><content><![CDATA[&lt;h1 id=&#34;randomstringlength-charset&#34;&gt;randomString(length, [charset])&lt;/h1&gt;
&lt;p&gt;Function returns a random string of a given length, optionally selected from a custom character set.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;length&lt;/td&gt;
              &lt;td&gt;int&lt;/td&gt;
              &lt;td&gt;Length of the random string&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;charset (optional)&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;A customized list of characters&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;any&lt;/td&gt;
              &lt;td&gt;Random item(s) from the array of characters&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { randomString } from &amp;#39;https://jslib.k6.io/k6-utils/1.2.0/index.js&amp;#39;;

export default function () {
  const randomFirstName = randomString(8);
  console.log(`Hello, my first name is ${randomFirstName}`);

  const randomLastName = randomString(10, `aeioubcdfghijpqrstuv`);
  console.log(`Hello, my last name is ${randomLastName}`);

  const randomCharacterWeighted = randomString(1, `AAAABBBCCD`);
  console.log(`Chose a random character ${randomCharacterWeighted}`);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="randomstringlength-charset">randomString(length, [charset])&lt;/h1>
&lt;p>Function returns a random string of a given length, optionally selected from a custom character set.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Parameter&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>length&lt;/td>
&lt;td>int&lt;/td>
&lt;td>Length of the random string&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>charset (optional)&lt;/td>
&lt;td>string&lt;/td>
&lt;td>A customized list of characters&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="returns">Returns&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>any&lt;/td>
&lt;td>Random item(s) from the array of characters&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="example">Example&lt;/h3>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import { randomString } from &amp;#39;https://jslib.k6.io/k6-utils/1.2.0/index.js&amp;#39;;
export default function () {
const randomFirstName = randomString(8);
console.log(`Hello, my first name is ${randomFirstName}`);
const randomLastName = randomString(10, `aeioubcdfghijpqrstuv`);
console.log(`Hello, my last name is ${randomLastName}`);
const randomCharacterWeighted = randomString(1, `AAAABBBCCD`);
console.log(`Chose a random character ${randomCharacterWeighted}`);
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div></description></item><item><title>uuidv4()</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/uuidv4/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/uuidv4/</guid><content><![CDATA[&lt;h1 id=&#34;uuidv4&#34;&gt;uuidv4()&lt;/h1&gt;
&lt;p&gt;Function returns a random uuid v4 in a string form.&lt;/p&gt;
&lt;h3 id=&#34;parameters&#34;&gt;Parameters&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Parameter&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Type&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;secure (optional)&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;boolean&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;By default, &lt;code&gt;uuidv4()&lt;/code&gt; uses a standard random number generator. If the &lt;code&gt;secure&lt;/code&gt; option is set to &lt;code&gt;true&lt;/code&gt;, &lt;code&gt;uuidv4&lt;/code&gt; uses a cryptographically secure random number generator instead. While this adds security, the &lt;code&gt;secure&lt;/code&gt; option also makes the function an order of magnitude slower.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Type&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;string&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Random UUID v4 string&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { uuidv4 } from &amp;#39;https://jslib.k6.io/k6-utils/1.4.0/index.js&amp;#39;;

export default function () {
  const randomUUID = uuidv4();
  console.log(randomUUID); // 35acae14-f7cb-468a-9866-1fc45713149a
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="uuidv4">uuidv4()&lt;/h1>
&lt;p>Function returns a random uuid v4 in a string form.&lt;/p>
&lt;h3 id="parameters">Parameters&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align: left">Parameter&lt;/th>
&lt;th style="text-align: left">Type&lt;/th>
&lt;th style="text-align: left">Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align: left">secure (optional)&lt;/td>
&lt;td style="text-align: left">boolean&lt;/td>
&lt;td style="text-align: left">By default, &lt;code>uuidv4()&lt;/code> uses a standard random number generator. If the &lt;code>secure&lt;/code> option is set to &lt;code>true&lt;/code>, &lt;code>uuidv4&lt;/code> uses a cryptographically secure random number generator instead. While this adds security, the &lt;code>secure&lt;/code> option also makes the function an order of magnitude slower.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="returns">Returns&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align: left">Type&lt;/th>
&lt;th style="text-align: left">Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align: left">string&lt;/td>
&lt;td style="text-align: left">Random UUID v4 string&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="example">Example&lt;/h3>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import { uuidv4 } from &amp;#39;https://jslib.k6.io/k6-utils/1.4.0/index.js&amp;#39;;
export default function () {
const randomUUID = uuidv4();
console.log(randomUUID); // 35acae14-f7cb-468a-9866-1fc45713149a
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div></description></item><item><title>findBetween(content, left, right, [repeat])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/findbetween/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/findbetween/</guid><content><![CDATA[&lt;h1 id=&#34;findbetweencontent-left-right-repeat&#34;&gt;findBetween(content, left, right, [repeat])&lt;/h1&gt;
&lt;p&gt;Function that returns a string from between two other strings.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;content&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;The string to search through (e.g. 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/response/&#34;&gt;Response.body&lt;/a&gt;)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;left&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;The string immediately before the value to be extracted&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;right&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;The string immediately after the value to be extracted&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;repeat (optional)&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;If &lt;code&gt;true&lt;/code&gt;, the result will be a string array containing all occurrences&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;The extracted string, or an empty string if no match was found. If &lt;code&gt;repeat=true&lt;/code&gt;, this will be an array of strings or an empty array&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { findBetween } from &amp;#39;https://jslib.k6.io/k6-utils/1.2.0/index.js&amp;#39;;

export default function () {
  const response = &amp;#39;&amp;lt;div class=&amp;#34;message&amp;#34;&amp;gt;Message 1&amp;lt;/div&amp;gt;&amp;lt;div class=&amp;#34;message&amp;#34;&amp;gt;Message 2&amp;lt;/div&amp;gt;&amp;#39;;

  const message = findBetween(response, &amp;#39;&amp;lt;div class=&amp;#34;message&amp;#34;&amp;gt;&amp;#39;, &amp;#39;&amp;lt;/div&amp;gt;&amp;#39;);

  console.log(message); // Message 1

  const allMessages = findBetween(response, &amp;#39;&amp;lt;div class=&amp;#34;message&amp;#34;&amp;gt;&amp;#39;, &amp;#39;&amp;lt;/div&amp;gt;&amp;#39;, true);
  console.log(allMessages.length); // 2
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="findbetweencontent-left-right-repeat">findBetween(content, left, right, [repeat])&lt;/h1>
&lt;p>Function that returns a string from between two other strings.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Parameter&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>content&lt;/td>
&lt;td>string&lt;/td>
&lt;td>The string to search through (e.g.
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/response/">Response.body&lt;/a>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>left&lt;/td>
&lt;td>string&lt;/td>
&lt;td>The string immediately before the value to be extracted&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>right&lt;/td>
&lt;td>string&lt;/td>
&lt;td>The string immediately after the value to be extracted&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>repeat (optional)&lt;/td>
&lt;td>boolean&lt;/td>
&lt;td>If &lt;code>true&lt;/code>, the result will be a string array containing all occurrences&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="returns">Returns&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>string&lt;/td>
&lt;td>The extracted string, or an empty string if no match was found. If &lt;code>repeat=true&lt;/code>, this will be an array of strings or an empty array&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="example">Example&lt;/h3>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import { findBetween } from &amp;#39;https://jslib.k6.io/k6-utils/1.2.0/index.js&amp;#39;;
export default function () {
const response = &amp;#39;&amp;lt;div class=&amp;#34;message&amp;#34;&amp;gt;Message 1&amp;lt;/div&amp;gt;&amp;lt;div class=&amp;#34;message&amp;#34;&amp;gt;Message 2&amp;lt;/div&amp;gt;&amp;#39;;
const message = findBetween(response, &amp;#39;&amp;lt;div class=&amp;#34;message&amp;#34;&amp;gt;&amp;#39;, &amp;#39;&amp;lt;/div&amp;gt;&amp;#39;);
console.log(message); // Message 1
const allMessages = findBetween(response, &amp;#39;&amp;lt;div class=&amp;#34;message&amp;#34;&amp;gt;&amp;#39;, &amp;#39;&amp;lt;/div&amp;gt;&amp;#39;, true);
console.log(allMessages.length); // 2
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div></description></item><item><title>normalDistributionStages(maxVus, durationSeconds, [numberOfStages])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/normaldistributionstages/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/normaldistributionstages/</guid><content><![CDATA[&lt;h1 id=&#34;normaldistributionstagesmaxvus-durationseconds-numberofstages&#34;&gt;normalDistributionStages(maxVus, durationSeconds, [numberOfStages])&lt;/h1&gt;
&lt;p&gt;Function to create 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/k6-options/#stages&#34;&gt;stages&lt;/a&gt; producing a &lt;em&gt;normal distribution (bell-curve)&lt;/em&gt; of VUs for a test.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;maxVus&lt;/td&gt;
              &lt;td&gt;int&lt;/td&gt;
              &lt;td&gt;Maximum virtual users at the height of the curve&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;durationSeconds&lt;/td&gt;
              &lt;td&gt;int&lt;/td&gt;
              &lt;td&gt;Overall duration for all stages combined&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;numberOfStages (optional)&lt;/td&gt;
              &lt;td&gt;int&lt;/td&gt;
              &lt;td&gt;Number of stages to create; default is &lt;code&gt;10&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;array[object]&lt;/td&gt;
              &lt;td&gt;An array of &lt;code&gt;{&amp;quot;duration&amp;quot;: &amp;quot;XXXs&amp;quot;, &amp;quot;target&amp;quot;: XXX}&lt;/code&gt; JSON objects representing stages&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { sleep } from &amp;#39;k6&amp;#39;;
import exec from &amp;#39;k6/execution&amp;#39;;
import { normalDistributionStages } from &amp;#39;https://jslib.k6.io/k6-utils/1.2.0/index.js&amp;#39;;

export const options = {
  // Alters the number of VUs from 1 to 10 over a period
  // of 20 seconds comprised of 5 stages.
  stages: normalDistributionStages(10, 20, 5),
};

export default function () {
  console.log(exec.instance.vusActive);
  sleep(1);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="normaldistributionstagesmaxvus-durationseconds-numberofstages">normalDistributionStages(maxVus, durationSeconds, [numberOfStages])&lt;/h1>
&lt;p>Function to create
&lt;a href="/docs/k6/v2.3.x/using-k6/k6-options/#stages">stages&lt;/a> producing a &lt;em>normal distribution (bell-curve)&lt;/em> of VUs for a test.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Parameter&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>maxVus&lt;/td>
&lt;td>int&lt;/td>
&lt;td>Maximum virtual users at the height of the curve&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>durationSeconds&lt;/td>
&lt;td>int&lt;/td>
&lt;td>Overall duration for all stages combined&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>numberOfStages (optional)&lt;/td>
&lt;td>int&lt;/td>
&lt;td>Number of stages to create; default is &lt;code>10&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="returns">Returns&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>array[object]&lt;/td>
&lt;td>An array of &lt;code>{&amp;quot;duration&amp;quot;: &amp;quot;XXXs&amp;quot;, &amp;quot;target&amp;quot;: XXX}&lt;/code> JSON objects representing stages&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="example">Example&lt;/h3>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import { sleep } from &amp;#39;k6&amp;#39;;
import exec from &amp;#39;k6/execution&amp;#39;;
import { normalDistributionStages } from &amp;#39;https://jslib.k6.io/k6-utils/1.2.0/index.js&amp;#39;;
export const options = {
// Alters the number of VUs from 1 to 10 over a period
// of 20 seconds comprised of 5 stages.
stages: normalDistributionStages(10, 20, 5),
};
export default function () {
console.log(exec.instance.vusActive);
sleep(1);
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div></description></item><item><title>check( val, sets, [tags] )</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/check/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/check/</guid><content><![CDATA[&lt;h1 id=&#34;check-val-sets-tags-&#34;&gt;check( val, sets, [tags] )&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;check&lt;/code&gt; function is a drop-in replacement for the built-in 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/check/&#34;&gt;check&lt;/a&gt;, with added support for async values. Any &lt;code&gt;Promise&lt;/code&gt;s will be awaited, and the result is reported once the operation has been completed.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;val&lt;/td&gt;
              &lt;td&gt;any&lt;/td&gt;
              &lt;td&gt;Value to test.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;sets&lt;/td&gt;
              &lt;td&gt;Record&amp;lt;string, any&amp;gt;&lt;/td&gt;
              &lt;td&gt;Tests (checks) to run on the value. Functions will be called. &lt;code&gt;Promise&lt;/code&gt;s will be awaited.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;tags (optional)&lt;/td&gt;
              &lt;td&gt;Record&amp;lt;string, string&amp;gt;&lt;/td&gt;
              &lt;td&gt;Extra tags to attach to metrics emitted.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Promise&lt;boolean&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;true&lt;/code&gt; if all checks have succeeded, &lt;code&gt;false&lt;/code&gt; otherwise. If any of the checked values was a &lt;code&gt;Promise&lt;/code&gt;, the result is wrapped in a &lt;code&gt;Promise&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;examples&#34;&gt;Examples&lt;/h3&gt;
&lt;p&gt;Using &lt;code&gt;check()&lt;/code&gt; with async values.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import http from &amp;#39;k6/http&amp;#39;;
import { fail } from &amp;#39;k6&amp;#39;;
import { check } from &amp;#39;https://jslib.k6.io/k6-utils/1.5.0/index.js&amp;#39;;

function waitFor(delay) {
  return new Promise((resolve) =&amp;gt; {
    setTimeout(() =&amp;gt; {
      resolve(true);
    }, delay);
  });
}

export default async function () {
  const res = http.get(&amp;#39;https://quickpizza.grafana.com/&amp;#39;);

  const success = await check(res, {
    &amp;#39;passing promise as a value&amp;#39;: waitFor(1000),
    &amp;#39;async function&amp;#39;: async (res) =&amp;gt; {
      await waitFor(500);

      return res.status === 200;
    },
  });

  if (!success) {
    fail(&amp;#39;check did not succeed&amp;#39;);
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For general usage of checks, refer to 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/check/#examples&#34;&gt;check(val, set, [tags])&lt;/a&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="check-val-sets-tags-">check( val, sets, [tags] )&lt;/h1>
&lt;p>The &lt;code>check&lt;/code> function is a drop-in replacement for the built-in
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6/check/">check&lt;/a>, with added support for async values. Any &lt;code>Promise&lt;/code>s will be awaited, and the result is reported once the operation has been completed.&lt;/p></description></item></channel></rss>