-2

I'm working on a script to search my Google Sheet for 0 on E Column and then delete the row, so far I have this:

function readRows() {
    var sheet = SpreadsheetApp.getActiveSheet();
    var rows = sheet.getDataRange();
    var numRows = rows.getNumRows();
    var values = rows.getValues();

    var rowsDeleted = 0;
    for (var i = 0; i <= numRows - 1; i++) {
        var row = values[i];
        if (row[4] == 0) {
            sheet.deleteRow((parseInt(i) + 1) - rowsDeleted);
            rowsDeleted++;
        }
    }
}

But this script delete rows with blank values as well I want to ignore these blank values

Heisenberg
  • 865
  • 10
  • 26
  • I don't have experience with Spreadsheets, but is there a difference between null and 0? – Luay Jan 15 '19 at 17:57

1 Answers1

2

Your comparison row[4] == 0 will return TRUE when the value is exactly 0 and anything evaluating to 0, in which case is a blank string.

Use strict equality checking to achieve the result you're after:

if (row[4] === 0) {

See also:

esqew
  • 42,425
  • 27
  • 92
  • 132