Search⌘ K
AI Features

Iterators and Destructuring

Explore how iterators and destructuring work in ES6 to manage iterable data. Learn the process of converting iterators to arrays, assigning elements through destructuring, and understand the behavior of leftover elements during assignment. This lesson prepares you for combining generators, deepening your grasp of dynamic data handling in JavaScript.

We'll cover the following...

When equating an array to an iterable, iteration takes place.

Node.js
let lampIterator = getLampIterator();
let [head,] = lampIterator;
console.log( head, [...lampIterator] );
//> red []

The destructuring assignment is executed as follows:

...