Search code examples
google-apps-scriptlimitrows

How to Limit the Amount of Rows in Google Apps Script?


Similar to the limit formula in Google Sheets:

=query(F1:F, "select F where F contains '5' limit 10")

How would I limit the amount of returning rows in Google Apps Script, when I want to limit the results? Here is what I have where it pastes my return rows, and the function works correctly, but I need to limit the results to 20:

 ws.getRange(6, 11, rows.length, rows[0].length).setValues(rows);

Any suggestions?


Solution

  • Limiting Rows

    var r=rows.slice(0,20);
    ws.getRange(6, 11, r.length, r[0].length).setValues(r);
    

    Array.slice