title: Trying to Set Value in For Loop - apps script
body: <p>I am trying to set the value of a cell in a column when two other columns at an index match values. How can I set the value using an index? (&lt;<strong>Edited</strong>)</p>
  <pre><code>  for (let i = 0; i &lt; assetId.length; i++) {
      for (let p = 0; p &lt; oldId.length; p++) {
        if (assetId[i] !=&quot;&quot; &amp;&amp; oldId[p] !=&quot;&quot;) {
          if (assetId[i] == oldId[p]) {
            Logger.log('Old Match: ' + assetId[i])
  
            //if match modify 4th column at row [i] to 'null'
        
       d.getRange(i,3).setValue('null')
          }
        }
      }
   }
  </code></pre>
  <p>Based on if assetId[i] == oldId[p], I am trying to change column F of row [i] to 'null'</p>
  <p><strong>Edit</strong> (examples requested)
  <a href="https://i.stack.imgur.com/gjjqw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gjjqw.png" alt="enter image description here" /></a></p>
  <p>Column J is oldId and K is newId
  <a href="https://i.stack.imgur.com/rwX2l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rwX2l.png" alt="enter image description here" /></a></p>
  <p>EXPECTED OUTPUT: F4 should be null</p>
  <p>Full code:</p>
  <pre><code>function replaceIds() {
  
     const ss = SpreadsheetApp.getActiveSpreadsheet()
     const r = ss.getSheetByName(&quot;Form Responses 1&quot;)
     const d = ss.getSheetByName(&quot;Devices&quot;)
  
     const oldId = r.getRange(&quot;J2:J&quot;).getValues().flat()
     const newId = r.getRange(&quot;K2:K&quot;).getValues().flat()
     const studentName = r.getRange(&quot;C2:C&quot;).getValues().flat()
  
     const assetId = d.getRange(&quot;G3:G&quot;).getValues().flat()
     const annotatedUser = d.getRange(&quot;E3:E&quot;).getValues().flat()
  
  
     for (let i = 0; i &lt; assetId.length; i++) {
       for (let p = 0; p &lt; oldId.length; p++) {
         if (assetId[i] !=&quot;&quot; &amp;&amp; oldId[p] !=&quot;&quot;) {
           if (assetId[i] == oldId[p]) {
             Logger.log('Old Match: ' + assetId[i])
             //if match modify 4th column at row [i] to 'null'
             d.getRange(i,3).setValue('null')
           }
         }
      }
  
      //new asset ID loop
      for (let r = 0; r &lt; newId.length; r++) {
        //Logger.log(oldId[p])
        if (assetId[i] !=&quot;&quot;) {
          if (newId[r] !=&quot;&quot;) {
            //Logger.log('## not null ##')
            if (assetId[i] == newId[r]) {
              Logger.log('New Match: ' + assetId[i])
            }
          }
        }
      }
    }
  }
  </code></pre>