JavaScript Internals (521 Qs)•Part 7: Execution Context, Functional JS & V8 Engine (404 - 463)
What are the built-in iterables
Below are the list of built-in iterables in javascript,
- Arrays and TypedArrays
- Strings: Iterate over each character or Unicode code-points
- Maps: iterate over its key-value pairs
- Sets: iterates over their elements
- arguments: An array-like special variable in functions
- DOM collection such as NodeList
Practical Code Example
javascript
// Built-in Iterables implementing [Symbol.iterator]:
const array = [1, 2, 3];
const string = "hello";
const map = new Map([['a', 1]]);
const set = new Set([1, 2, 3]);
for (const char of string) console.log(char); // Iterates 'h', 'e', 'l', 'l', 'o'