JS: Iterable Interface
Object having Iterable Interface is called Iterable Object.
It must have the property Symbol.iterator, owned or inherited.
Iterable Interface Properties
Symbol.iterator-
Symbol.iteratoris a Symbol.- Value must be a function.
- This function's return value must be an object that conforms to the Iterator Interface.
Example
array is iterable object.
Because it has inherited property key Symbol.iterator.
// array has an inherited property key Symbol.iterator console.log(Reflect.has([3, 4], Symbol.iterator)); // not its own property console.log(Object.hasOwn([3, 4], Symbol.iterator) === false); // the property Symbol.iterator of array is inherited from Array.prototype console.log(Object.hasOwn(Array.prototype, Symbol.iterator)); // true
JavaScript. Iterable, Iterator
- JS: Iterable Object
- JS: for-of Loop
- JS: Array.from
- JS: Spread Operator (triple dots)
- JS: Iterator
- JS: Iterator.prototype
- JS: Generator
- JS: Generator Function (asterisk)
- JS: Interface
- JS: Iterable Interface
- JS: Iterator Interface
- JS: IteratorResult Interface
- JS: Test If Object is Iterable or Iterator 📜