title: How to get the specific range of row data from google sheet through apps script
body: <p>I am trying to fetch some range of data from google sheet via app script.<br>
  Let's have an example. I have 96 data rows in google sheet, I want to fetch 10 rows.<br>
  From Front-end side the call is based on scrolling event to fetch every next 10 row data.<br>
  I have tried below code.<br></p>
  <pre><code>function doGet(request){
    var ss = SpreadsheetApp.openById(&quot;MY SHEET ID&quot;);
    var sheet = ss.getSheetByName(&quot;Products&quot;);
    return getUsers(sheet,request); 
  }
  
  function getUsers(sheet,request){
    var jo = {};
    var dataArray = [];
    // every time from, where is passed from Frontend, like 2-10, 12-10, 22-10, etc...
    var from = request.parameter.from;
    var where = request.parameter.where;
    // by this if condition, getting data from 1 to 90
    if((sheet.getLastRow()-1)&gt;=(from+where)){
      var rows = sheet.getRange(from,1,from+where, sheet.getLastColumn()).getValues();
      for(var i = 0, l= rows.length; i&lt;l ; i++){
        var dataRow = rows[i];
        var record = {};
        record['ProductId'] = dataRow[0];
        // ...
        // some more column data fetching here
        // ...
        dataArray.push(record);
      }  
      jo.user = dataArray;
      var result = JSON.stringify(jo);
      return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.JSON);
    }
    // tried to get last 6 data through below code
    else{
      if(from &lt;= (sheet.getLastRow() - 1)){
        var rows = sheet.getRange(from,1,sheet.getLastRow()-1, sheet.getLastColumn()).getValues();
        for(var i = 0, l= rows.length; i&lt;l ; i++){
          var dataRow = rows[i];
          var record = {};
          record['ProductId'] = dataRow[0];
          // ...
          // some more column data fetching here
          // ...
          dataArray.push(record);
        }  
        jo.user = dataArray;
        var result = JSON.stringify(jo);
        return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.JSON);
      }
    }
  }  
  </code></pre>
  <p>By this code, I am getting values up to 90 with chunks of 10 rows, but at the end, the last 6 data I am not able to get.<br>
  Is there any logic to get those records? I have tried to achieve through last <code>if</code> statement but couldn't get.<br>
  Thanks in Advance!</p>
  <p><strong>Edit:</strong><br>
  as per the solution from <a href="https://stackoverflow.com/a/62588597/6911538">Taniake</a>, Getting ProductId column perfectly, <br>
  Moreover, If there are multiple columns like ProductId, ProductName, ProductImage, etc..<br>
  Range Might be <br>From <br></p>
  <pre><code>const values = sheet.getRange(from, 1, sheet.getLastRow() - from - where &gt;= 0 ? where : sheet.getLastRow() - from + 1, 1).getValues();
  </code></pre>
  <p>To
  <br></p>
  <pre><code>const values = sheet.getRange(from, 1, sheet.getLastRow() - from - where &gt;= 0 ? where : sheet.getLastRow() - from + 1, sheet.getLastColumn()).getValues();
  </code></pre>
  <br>
  how to map those values to JSON constant namely "result" in the solution provided?