title: Finding index of an element in a specified array
body: <p>I'm in the making of a google sheets app script where I want to check if a value from one cell is in an array of values, then find what the index is so I can direct my function to that cell.</p>
  <p>I'm at the point where I have my array in a variable called <code>distArray</code>, and I want to check if <code>&quot;id&quot;</code> is in that array.</p>
  <p>Here's the code to better visualize:</p>
  <pre><code>function logs() {
    let app = SpreadsheetApp
    let dest = app.getActiveSpreadsheet().getSheetByName(&quot;Baza Danych&quot;);
    let lastrow = dest.getLastRow();
  
    let destArr = dest.getRange(2, 1, lastrow).getValues();
    let id = app.getActiveSpreadsheet().getSheetByName(&quot;Zgloszenia&quot;).getRange(6, 2).getValue();
    let position = destArr.indexOf(id);
  
    Logger.log(id)
    Logger.log(destArr)
    Logger.log(position)
  }
  </code></pre>
  <p>And <a href="https://i.stack.imgur.com/fdRSc.png" rel="nofollow noreferrer">here is the output</a> I get.</p>
  <p>My problem is that no matter what the value of <code>&quot;id&quot;</code> is, the index is either <code>-1</code> or <code>0</code> meaning the value either is not in the array or is in the first cell.</p>