Skip to content

Diagnostic reference

TypeError: X is not iterable

Fix TypeError: X is not iterable in Google Apps Script when looping with for...of over a Range, FileIterator, null lookup, or plain object.

Updated December 6, 2026

Apps Script error

TypeError: sheet.getDataRange() is not iterable

What it means

JavaScript's for...of loop and spread syntax ([...x]) only work on iterable values such as arrays, strings, Maps, and Sets. In Apps Script, Range objects, DriveApp FileIterator/FolderIterator objects, null results, and plain objects are not iterable, so passing them to for...of throws this TypeError.

Related error messages

  • TypeError: files is not iterable
  • TypeError: range is not iterable
  • TypeError: Cannot iterate over null or undefined

Before and after

The code before and after the fix.

Problem 2 changed lines
function logCustomerNames() {
  const sheet = SpreadsheetApp.getActiveSheet();
  // getDataRange() returns a Range object, not a 2D array of rows.
  for (const row of sheet.getDataRange()) {
    Logger.log(row[0]);
  }
}
Fixed 2 changed lines
function logCustomerNames() {
  const sheet = SpreadsheetApp.getActiveSheet();
  const rows = sheet.getDataRange().getValues();
  for (const row of rows) {
    Logger.log(row[0]);
  }
}

How to fix it

  • For a Spreadsheet Range, call .getValues() (or .getDisplayValues()) first so you iterate over the 2D array of rows.
  • For DriveApp.getFiles(), getFolders(), or searchFiles(), loop with while (files.hasNext()) { const file = files.next(); ... } instead of for...of.
  • For plain objects (such as PropertiesService.getScriptProperties().getProperties()), iterate with Object.entries(obj) or Object.keys(obj).
  • If the value comes from a helper or lookup, guard null or undefined before looping.

Things to check

  • myFunction checks for...of targets against Apps Script type declarations in the editor, flagging non-iterable Range and FileIterator objects before you run the script.

In the Apps Script editor

Catch errors like this before clicking Run.

myFunction (published as Error Checker for Google Apps Script on the Chrome Web Store) checks your code while you edit at script.google.com. Diagnostics, autocomplete, and rule-based quick fixes are free without an account, run in your browser, and request no Google Drive, Gmail, or Apps Script project OAuth scopes. Writing Apps Script with an AI coding agent? Connect the Apps Script MCP server to run the same static checks before pasting code.