title: Sorted 2D array sorting again on check
body: <p>I'm using Google Sheets and trying to confirm, using Google Apps Script, that a range is sorted by the last name (second column).<br />
  However, there are duplicates in the second column and, when performing the check, the data is re-sorting before the check, flipping the position of rows where the last name matches, at which point the lists don't match.<br />
  For instance, the Sheets range is as follows:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>First Name</th>
  <th>Last Name</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td><em>Frida</em></td>
  <td>Acosta</td>
  </tr>
  <tr>
  <td><em>Autumn</em></td>
  <td>Acosta</td>
  </tr>
  <tr>
  <td><strong>Edgar</strong></td>
  <td>Andersen</td>
  </tr>
  <tr>
  <td><strong>Kayla</strong></td>
  <td>Andersen</td>
  </tr>
  <tr>
  <td>Raphael</td>
  <td>Andrade</td>
  </tr>
  <tr>
  <td>Johnathon</td>
  <td>Andrews</td>
  </tr>
  <tr>
  <td>Danielle</td>
  <td>Archer</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>As you can see, rows {1,2} and {3,4} have the same last name. But I've sorted the data on Last Name from Sheets, so this should be correct. However, when I run the code it resorts and flips them, so that it sorts to:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>First Name</th>
  <th>Last Name</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Autumn</td>
  <td>Acosta</td>
  </tr>
  <tr>
  <td>Frida</td>
  <td>Acosta</td>
  </tr>
  <tr>
  <td>Kayla</td>
  <td>Andersen</td>
  </tr>
  <tr>
  <td>Edgar</td>
  <td>Andersen</td>
  </tr>
  <tr>
  <td>Raphael</td>
  <td>Andrade</td>
  </tr>
  <tr>
  <td>Johnathon</td>
  <td>Andrews</td>
  </tr>
  <tr>
  <td>Danielle</td>
  <td>Archer</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>and now, obviously, they do not match.</p>
  <p>How can I check to see if a 2d array is sorted on a single column without having this happen where it attempts to re-sort the array?</p>
  <pre><code>function myFunction() {
    const ss = SpreadsheetApp.getActive().getActiveSheet();
    let a1 = ss.getRange(4,1,502,5).getValues();
    let a2 = JSON.stringify(a1);
    a1.sort((a, b) =&gt; a[1] &gt; b[1] ? 1 : -1);
    Logger.log(JSON.stringify(a1) == a2);
  }
  </code></pre>
  <p><a href="https://docs.google.com/spreadsheets/d/1FJBbenoiT893yVPFlbYNkqKkyzUtisHc26iRujTpHRo/edit#gid=0" rel="nofollow noreferrer">Test Sheet</a></p>