⊗jsSpItInv 62 of 294 menu

Iterator Invocation in JavaScript

Each sequential call of the iterator should return an object of a special structure. Let's examine it. Let's say we have an array:

let arr = [1, 2, 3];

Let's get the array iterator into a variable:

let iter = arr[Symbol.iterator]();

Now this variable contains an object with a method next. This method will return an object with a key value, containing the value of the element, and a key done, containing information about whether the iteration has finished or not:

console.log( iter.next() ); // {value: 1, done: false}

Sequential calls of the next method will yield the next element each time:

console.log( iter.next() ); // {value: 1, done: false} console.log( iter.next() ); // {value: 2, done: false} console.log( iter.next() ); // {value: 3, done: false}

And as soon as the elements run out, we will see the following values:

console.log( iter.next() ); // {value: undefined, done: true}

Get the iterator of the Map collection. Call it sequentially until the collection elements are exhausted.

Get the iterator of the NodeList collection. Call it sequentially until the collection elements are exhausted.

Get the iterator of the HTMLCollection collection. Call it sequentially until the collection elements are exhausted.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline