title: Using karate.forEach and karate.set to extract index of value from json array
body: <p>I have the below json:</p>
  
  <pre><code>{
    "id": [
      "1A",
      "2B"
    ],
    "name": [
      "rs",
      "mk"
    ]
  }
  </code></pre>
  
  <p>I want to extract the id value when name is 'rs' or 'mk'. There will be no duplication of <code>name</code> values and the size of <code>id</code> and <code>name</code> keys will always match. </p>
  
  <p>So i have created the following scenario where:<br>
  - I iterate through the <code>name</code> array using forEach.<br>
  - Find if the value of <code>name</code> matches <code>rs</code> or <code>mk</code> and if it does, retrieve the index.<br>
  - Then use this index to find the retrieve the value from <code>id</code> key.  </p>
  
  <p>When I run this, the <code>name_rs_idx</code> and <code>name_mk_idx</code> are not being set and are blank. </p>
  
  <pre><code>Scenario: Using forEach and karate.set
      * def vals = { id: ['1A', '2B'], name: ['rs', 'mk'] }
      * def name_rs_idx = ''
      * def rsFun =
        """
          function(x, i) {
            if(x == 'rs') {
              karate.set(name_rs_idx, i);
            }
          }
        """
      * karate.forEach(vals.name, rsFun)
      * print 'RS Index - ' +  name_rs_idx
      * def name_rs_id = vals.id[name_rs_idx]
      * print 'RS id -' + name_rs_id
  
      * def name_mk_idx = ''
      * def mkFun =
      """
        function(x, i) {
          if(x == 'mk') {
            karate.set(name_mk_idx, i);
          }
        }
      """
      * karate.forEach(vals.name, mkFun)
      * print 'MK Index - ' + name_mk_idx
      * def name_mk_id = vals.id[name_mk_idx]
      * print 'MK id -' + name_mk_id
  </code></pre>
  
  <p>Maybe i am not using the forEach function correctly or logic is incorrect.</p>