TypeError: object is not iterable
Quick summary
You spread {...obj} or ran for...of on a plain object — objects are not iterable by default.
Why this happens
Spreading a plain object into an array: [...obj]
Using for...of on an object instead of for...in or Object.entries
Passing a non-iterable to a function expecting an iterable (Array.from, new Set)
Minimal example
const obj = { a: 1, b: 2 };
const arr = [...obj]; // TypeError: obj is not iterableconst obj = { a: 1, b: 2 };
const arr = [...Object.entries(obj)]; // [['a',1],['b',2]]Plain objects have no Symbol.iterator, so spreading them fails. Object.entries returns an iterable array of pairs that can be spread.
How to diagnose
Read the TypeError: 'object is not iterable (cannot read property Symbol.iterator)'
Check whether the value is an array or has a Symbol.iterator
Use Array.isArray or typeof to confirm the value type
How to fix
Use Object.entries/keys/values to iterate object data
Convert with Array.from if the value is array-like
Implement Symbol.iterator on custom classes that should be iterable
How to prevent
Use for...in or Object.entries for objects, for...of for arrays
Check iterability before spreading unknown values