title: K6 - iterate over array, but not for each VU
body: <p>I am working on a script to test my infra using <a href="https://k6.io" rel="nofollow noreferrer">k6</a>.</p>
  <p>I would like each VU be assigned to a previous known <code>id</code> obtained from an existing array and that VU execute the instructions from the <code>default</code> function only once at the time the VU is created.</p>
  <p>How to iterate over this array, get the <code>id</code> and use it for each VU created by the script?</p>
  <p>The initial idea is bellow, but I am sure it is not correct.</p>
  <pre><code>export let options = {
      stages: [
          { duration: '10s', target: 1 },
          { duration: '10s', target: 10 },
      ],
  };
  
  const ids = [
      {'id':1, 'name':'name1'},
      {'id':3, 'name':'name3'},
      {'id':4, 'name':'name4'},
      {'id':18, 'name':'name18'}];
  
  export default function () {
      for(var i=0; i&lt;ids.length; i++) {
          var user = ids[i];
          //do something with user.id
      }
  }
  </code></pre>
  <p>According to K6 manual, each VU will execute everything is inside the <code>default</code> function, but it would make all VU's execute the for loop and it is not the behavior I want.</p>
  <p>I want the VU execute what is inside the for, but using a different id for each new VU. Something like bellow:</p>
  <pre><code>export default function () {
      var user = ids[i];
      //do something with user.id
  }
  </code></pre>