‘How to Fix “is not iterable” in JavaScript’
The console shows TypeError: data is not iterable when the value passed to for...of, array destructuring, or spread syntax is not iterable. An iterable is a value that can be read one item at a time (see the iterable definition in MDN's for…of page). It appears, for example, when you loop over a list returned by fetch. Passing a plain object or undefined causes this error. Either point to the property that holds the array, or convert the object to an array with Object.entries, and the error goes away.
This article covers a case where I fetched a list from an API, looped over it with for...of to render it on the page, and the display stayed stuck at "Loading…". In my test environment, I triggered this error with for...of, array destructuring, and spread syntax, and I copied the messages exactly as they appeared. I also confirmed that after the fix, the error disappears and the list is displayed.
The test environment was Ubuntu 24.04 and Node.js 22.23.4. I served the page and the JSON file with Python 3.11's http.server, and I used the JSON file in place of the API's response. The browser was Chromium 153, launched with Playwright 1.63.0. I took the console messages through the DevTools protocol and also captured screenshots of the DevTools panel. I did not test Firefox or Safari, and I did not test with React, Vite, or other tooling. I also did not test fetching from a real API server.
- 1. The error from looping over an object with for…of
- 2. A misspelled property name leads to looping over undefined
- 3. Use Object.entries for an object keyed by ID
- 4. With array destructuring, the message changes when the value is undefined
- 5. Spread syntax gives the same error inside an array
- 6. Identifying the cause from the message
The error from looping over an object with for…of
I put a single paragraph on the page to display the list:
<p id="list">読み込み中…</p>
<script type="module" src="main.js"></script>
In place of the API response, I prepared the following items.json. The array of products is in a property called items, and the outermost value is an object.
{
"items": [
{ "id": "a1", "name": "りんご" },
{ "id": "b2", "name": "みかん" },
{ "id": "c3", "name": "ぶどう" }
],
"total": 3
}
In main.js, I assumed the response itself was an array, so I looped over data with for...of:
const list = document.getElementById('list');
async function showItems() {
const res = await fetch('items.json');
const data = await res.json();
const names = [];
for (const item of data) {
names.push(item.name);
}
list.textContent = names.join('、');
}
showItems();
When I opened the page, the display stayed at "Loading…", and the DevTools Console panel showed the following:
Uncaught (in promise) TypeError: data is not iterable
at showItems (main.js:7:22)

data is not iterable means that data is not iterable. According to MDN's explanation of the "is not iterable" error, arrays, strings, and Maps are iterable, but plain objects are not. That is why you cannot loop over an object with for...of.
The (main.js:7:22) on the second line of the message is the position in main.js: line 7, column 22, which is the data in for (const item of data). The column count includes the two leading spaces. showItems is the name of the function where the error occurred.
The leading Uncaught (in promise) appeared because the error happened inside an async function. When I looped over an object with for...of right after the page loaded, without using an async function, the (in promise) part was missing and the message was Uncaught TypeError: data is not iterable.
To fix this, point to the property that holds the array. Changing line 7 as follows removed the error, and the page displayed "apple, mandarin, grape" (the Japanese names in items.json):
for (const item of data.items) {
A misspelled property name leads to looping over undefined
I also tried writing data.item instead of data.items on line 7. This produced the same kind of error:
Uncaught (in promise) TypeError: data.item is not iterable
at showItems (main.js:7:27)
items.json has no property called item, so data.item is undefined. The message does not say undefined. Instead, it shows the expression as written, data.item. The message looks similar to the data is not iterable error for objects. So compare the expression name in the message with the property names in the JSON to find the typo.
Use Object.entries for an object keyed by ID
Next, I tried a case where the list comes back as an object keyed by ID instead of as an array. I loaded the following items-by-id.json:
{
"a1": { "name": "りんご" },
"b2": { "name": "みかん" },
"c3": { "name": "ぶどう" }
}
I tried to get the ID and the product together with for (const [id, item] of data), which produced Uncaught (in promise) TypeError: data is not iterable (at main.js:7:28). This shape has no array property to loop over.
As MDN's Object.entries() page explains, Object.entries returns an array of the object's key-value pairs. You can loop over that array with for...of. Changing line 7 as follows removed the error, and the page displayed "a1:apple, b2:mandarin, c3:grape":
for (const [id, item] of Object.entries(data)) {
MDN's explanation of the error also recommends Object.keys or Object.entries for looping over the properties of an object.
With array destructuring, the message changes when the value is undefined
The right-hand side of array destructuring (const [first, second] = …) also needs an iterable value. I tried to get the first two items from items.json like this:
const [first, second] = data;
list.textContent = `${first.name}、${second.name}`;
Because data is an object, I got the same Uncaught (in promise) TypeError: data is not iterable as with for...of (at main.js:6:27).
When I wrote data.item on the right-hand side, which made the value undefined, the message changed:
Uncaught (in promise) TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
at showItems (main.js:6:27)

Unlike the for...of case, the message does not show the expression name data.item. It shows the value undefined instead. To find which expression was undefined, use the position on the second line of the message: line 6, column 27, which is the start of data.item after = . Changing the right-hand side to data.items removed the error, and the page displayed "apple, mandarin".
Spread syntax gives the same error inside an array
Spread syntax, written with ... inside an array literal, also requires an iterable value. I tried to append a property called extra, which does not exist in items.json, as additional products after the existing ones:
const all = [...data.items, ...data.extra];
Because data.extra is undefined, I got Uncaught (in promise) TypeError: data.extra is not iterable (at main.js:6:39). When I loaded items-by-id.json and wrote [...data], I got data is not iterable.
Spreading into a function argument, as in names.push(...data.item), added a different phrase to the end of the message:
Uncaught (in promise) TypeError: data.item is not iterable (cannot read property undefined)
at showItems (main.js:7:9)
On the other hand, using ... inside an object literal, as in { ...data.extra, total: data.total }, did not produce an error even when data.extra was undefined. The page displayed {"total":3}. So the same ... causes an error only when it spreads into an array or into function arguments.
If a response without extra is valid and you want to handle that case, use an empty array when the property is missing. As MDN's explanation of the nullish coalescing operator (??) describes, ?? returns the right-hand side when the left-hand side is null or undefined. Changing line 6 as follows removed the error, and the page displayed "apple, mandarin, grape":
const all = [...data.items, ...(data.extra ?? [])];
Use ?? [] only for properties that you know may be missing. In my test environment, I added ?? [] to the misspelled property and wrote [...(data.item ?? [])]. No error appeared, and the list was empty. Because the console shows nothing, the typo is harder to notice.
Identifying the cause from the message
According to MDN's explanation of the error, the exact wording of the message differs between browsers. The x is not iterable form is used by browsers based on V8 and by Firefox. Safari shows different wording, such as undefined is not a function (near '...y of x...').
Here is a summary of the messages I saw in Chromium and their causes:
| Message | Example cause | Fix |
|---|---|---|
data is not iterable |
An object was passed to for...of, array destructuring, or array spread |
Point to the array property (data.items), or convert the object to an array with Object.entries |
data.item is not iterable |
A missing property (undefined) was passed to for...of or array spread |
Correct the typo in the property name |
data.item is not iterable (cannot read property undefined) |
A missing property was spread into a function argument (names.push(...data.item)) |
Correct the typo in the property name |
undefined is not iterable (cannot read property Symbol(Symbol.iterator)) |
The right-hand side of array destructuring was undefined |
Use the line and column in the message to find the expression, then correct the property name |





