title: Using Object keys to compare against data set and insert object values
body: <p><em>Thank you in advance!</em></p>
  <p><strong>Goal/Help Request:</strong></p>
  <p>I'd like to use the array I have in my code (which I think is an object literal?) and if a <strong>exact match</strong> occurs from the data set (Food column), it inserts the paired answer from the array into the &quot;Pairing&quot; column.</p>
  <p><strong>Issue/Thoughts:</strong></p>
  <p>I think I need to use Object.values()&amp; Object.keys(). I'm having a difficult time trying to get my function to run through the data and compare....I thought a for statement would work but it doesn't seem so and my forEach code says it's not a function and I'm a bit lost on how to have it go through each corresponding row like you would do with i++.</p>
  <p><strong>Sheet before script:</strong></p>
  <p><a href="https://i.stack.imgur.com/6Yqfx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6Yqfx.png" alt="enter image description here" /></a></p>
  <p><strong>Desired output:</strong></p>
  <p><a href="https://i.stack.imgur.com/yfzK2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yfzK2.png" alt="enter image description here" /></a></p>
  <p><strong>Data:</strong></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">Food</th>
  <th style="text-align: center;">Pairing</th>
  <th style="text-align: right;">Cost</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">apple toast</td>
  <td style="text-align: center;"></td>
  <td style="text-align: right;"></td>
  </tr>
  <tr>
  <td style="text-align: left;">apple cheese</td>
  <td style="text-align: center;"></td>
  <td style="text-align: right;"></td>
  </tr>
  <tr>
  <td style="text-align: left;">orange</td>
  <td style="text-align: center;"></td>
  <td style="text-align: right;"></td>
  </tr>
  <tr>
  <td style="text-align: left;">orange peel</td>
  <td style="text-align: center;"></td>
  <td style="text-align: right;"></td>
  </tr>
  <tr>
  <td style="text-align: left;">apple apple apple</td>
  <td style="text-align: center;"></td>
  <td style="text-align: right;"></td>
  </tr>
  <tr>
  <td style="text-align: left;">orange orange</td>
  <td style="text-align: center;"></td>
  <td style="text-align: right;"></td>
  </tr>
  <tr>
  <td style="text-align: left;">orange toast</td>
  <td style="text-align: center;"></td>
  <td style="text-align: right;"></td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><strong>CODE:</strong></p>
  <pre><code>    function apples() {
        sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
            const combo = {
                            'apple toast':'juice',
                            'apple cheese':'water',
                            'orange':'milk',
                            'orange peel':'OJ'
                            }
      const food = sheet.getRange(&quot;A2:A5&quot;).getValues().flat();
      const foodrownum = sheet.getDataRange().getNumRows();
      const pairing = sheet.getRange(&quot;B2:B5&quot;);
  
      var keys = Object.keys(combo)
  
      combo.forEach(function(item,index,array){
            if(item===food){
                sheet.getRange(2,2,foodrownum).setValue(Object.values(combo));
            }
      });
  
      }//end of function
  </code></pre>
  <p><strong>References:</strong></p>
  <ol>
  <li><a href="https://stackoverflow.com/questions/6243736/how-to-access-individual-elements-of-a-javascript-object-literal">how to access individual elements of a javascript object literal?</a></li>
  <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide</a></li>
  <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#object_literals" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#object_literals</a></li>
  </ol>