SlideShare a Scribd company logo
2
Most read
ITERABLES
& ITERATORS
in JAVASCRIPT
JS NUGGETS
Iterables, is a data structure that provides a way
to expose its data to the public.
This is done by implementing a method whose key is
Symbol.iterator, which is a factory for iterators.
// Variable ‘fruits’ has an Iterable list
const fruits = [' 🍎', ' 🍐', ' 🍊'];
Iterator, is a pointer for traversing the elements
of a data structure.
// Creating an Iterator ‘fruitIterator’
const fruitIterator = fruits[Symbol.iterator]();
Iterator object has a next() method which returns
the next item in the sequence.
This method returns an object with two properties,
done and value.
When next() call reaches to the end of sequence
then the done property set to true else remain
false.
fruitIterator.next();
// {value: " 🍎", done: false}
fruitIterator.next();
// {value: " 🍐", done: false}
fruitIterator.next();
// {value: " 🍊", done: false}
// Returns done as true when there is no element to
return
fruitIterator.next();
// {value: undefined, done: true}
Without iterable, it is really difficult to manage
the iteration on data for various types of data
structures.
For instance, iteration on an Array is different
from iteration on an Object.
And now with the introduction of new data
structures like Sets and Maps in ES6, it is really
going to be more complicated.
Two things to look for while using iterables,
Data consumer - How the iteration takes place.
(Loops, Spread operator, Array.from
method, Destructuring via an array
pattern, etc.)
Data source - What data structure we choose.
(Array, Objects, Set, Maps, etc.)
But, do we really need an
iterable?

More Related Content

PPTX
Database Connectivity in PHP
Taha Malampatti
 
PDF
Limited return type covariance and argument type contravariance
nob f
 
PDF
Dependency Injection
Rifat Nabi
 
PPT
Mysocial databasequeries
Program in Interdisciplinary Computing
 
PPT
Mysocial databasequeries
Program in Interdisciplinary Computing
 
PDF
Mysql & Php
Inbal Geffen
 
PDF
The Human Linter
Ilya Gelman
 
PDF
Introduction to php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
Database Connectivity in PHP
Taha Malampatti
 
Limited return type covariance and argument type contravariance
nob f
 
Dependency Injection
Rifat Nabi
 
Mysocial databasequeries
Program in Interdisciplinary Computing
 
Mysocial databasequeries
Program in Interdisciplinary Computing
 
Mysql & Php
Inbal Geffen
 
The Human Linter
Ilya Gelman
 
Introduction to php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 

Similar to Iterables and Iterators in JavaScript (20)

PDF
Andrii Orlov "Generators Flexibility in Modern Code"
LogeekNightUkraine
 
PDF
How I started to love design patterns
Samuel ROZE
 
PDF
React JS Hooks Sheet .pdf
nishant078cs23
 
DOCX
Pro.docx
ChantellPantoja184
 
PDF
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
anujsharmaanuj14
 
DOC
Ad java prac sol set
Iram Ramrajkar
 
PPTX
Getting the Most Out of jQuery Widgets
velveeta_512
 
PDF
Using and reusing CakePHP plugins
Pierre MARTIN
 
PDF
How I started to love design patterns
Samuel ROZE
 
PDF
Doctrine For Beginners
Jonathan Wage
 
PDF
Strategies for Mitigating Complexity in React Based Redux Applicaitons
garbles
 
PDF
TYPO3 Flow: Beyond the Blog Example (Inspiring Flow 2013)
Robert Lemke
 
KEY
amsterdamjs - jQuery 1.5
mennovanslooten
 
PDF
The Human Linter — Ilya Gelman
500Tech
 
PDF
Single Page Applications in Angular (italiano)
Fabio Biondi
 
PDF
How kris-writes-symfony-apps-london
Kris Wallsmith
 
PDF
Building Large jQuery Applications
Rebecca Murphey
 
PDF
Simpan data- ke- database
Tri Sugihartono
 
PDF
This project calls for the modification of the DollarFormat clas.pdf
jibinsh
 
DOCX
Final report mobile shop
Viditsingh22
 
Andrii Orlov "Generators Flexibility in Modern Code"
LogeekNightUkraine
 
How I started to love design patterns
Samuel ROZE
 
React JS Hooks Sheet .pdf
nishant078cs23
 
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
anujsharmaanuj14
 
Ad java prac sol set
Iram Ramrajkar
 
Getting the Most Out of jQuery Widgets
velveeta_512
 
Using and reusing CakePHP plugins
Pierre MARTIN
 
How I started to love design patterns
Samuel ROZE
 
Doctrine For Beginners
Jonathan Wage
 
Strategies for Mitigating Complexity in React Based Redux Applicaitons
garbles
 
TYPO3 Flow: Beyond the Blog Example (Inspiring Flow 2013)
Robert Lemke
 
amsterdamjs - jQuery 1.5
mennovanslooten
 
The Human Linter — Ilya Gelman
500Tech
 
Single Page Applications in Angular (italiano)
Fabio Biondi
 
How kris-writes-symfony-apps-london
Kris Wallsmith
 
Building Large jQuery Applications
Rebecca Murphey
 
Simpan data- ke- database
Tri Sugihartono
 
This project calls for the modification of the DollarFormat clas.pdf
jibinsh
 
Final report mobile shop
Viditsingh22
 
Ad

More from Ideas2IT Technologies (20)

PDF
Version comaparison in JavaScript
Ideas2IT Technologies
 
PDF
Currying in JavaScript
Ideas2IT Technologies
 
PDF
JS Testing Frameworks
Ideas2IT Technologies
 
PDF
Cool usage of Encoding and Decoding a URI in Javascript
Ideas2IT Technologies
 
PDF
String comparison in javascript
Ideas2IT Technologies
 
PDF
JavaScript symbols
Ideas2IT Technologies
 
PDF
Json.parse() in JavaScript
Ideas2IT Technologies
 
PDF
Bubble sort in Java Script
Ideas2IT Technologies
 
PDF
Performance analysis in merging arrays - JavaScript
Ideas2IT Technologies
 
PDF
Nullish coalescing in JavaScript
Ideas2IT Technologies
 
PDF
Conditionally add keys in JavaScript
Ideas2IT Technologies
 
PDF
What is Big O in JavaScript - Part-1
Ideas2IT Technologies
 
PDF
Variable hoisting in JavaScript
Ideas2IT Technologies
 
PDF
Formidable ES6 spread operator in JavaScript
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-5
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-4
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-3
Ideas2IT Technologies
 
PDF
Logging in JavaScript - part-2
Ideas2IT Technologies
 
PDF
Logging in JavaScript - part-1
Ideas2IT Technologies
 
PDF
Array vs set in JavaScript
Ideas2IT Technologies
 
Version comaparison in JavaScript
Ideas2IT Technologies
 
Currying in JavaScript
Ideas2IT Technologies
 
JS Testing Frameworks
Ideas2IT Technologies
 
Cool usage of Encoding and Decoding a URI in Javascript
Ideas2IT Technologies
 
String comparison in javascript
Ideas2IT Technologies
 
JavaScript symbols
Ideas2IT Technologies
 
Json.parse() in JavaScript
Ideas2IT Technologies
 
Bubble sort in Java Script
Ideas2IT Technologies
 
Performance analysis in merging arrays - JavaScript
Ideas2IT Technologies
 
Nullish coalescing in JavaScript
Ideas2IT Technologies
 
Conditionally add keys in JavaScript
Ideas2IT Technologies
 
What is Big O in JavaScript - Part-1
Ideas2IT Technologies
 
Variable hoisting in JavaScript
Ideas2IT Technologies
 
Formidable ES6 spread operator in JavaScript
Ideas2IT Technologies
 
Logging in JavaScript - Part-5
Ideas2IT Technologies
 
Logging in JavaScript - Part-4
Ideas2IT Technologies
 
Logging in JavaScript - Part-3
Ideas2IT Technologies
 
Logging in JavaScript - part-2
Ideas2IT Technologies
 
Logging in JavaScript - part-1
Ideas2IT Technologies
 
Array vs set in JavaScript
Ideas2IT Technologies
 
Ad

Recently uploaded (20)

PDF
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PPT
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PPTX
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
DOCX
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
Exploring AI Agents in Process Industries
amoreira6
 
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
Become an Agentblazer Champion Challenge
Dele Amefo
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
Presentation about variables and constant.pptx
safalsingh810
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 

Iterables and Iterators in JavaScript

  • 2. Iterables, is a data structure that provides a way to expose its data to the public. This is done by implementing a method whose key is Symbol.iterator, which is a factory for iterators. // Variable ‘fruits’ has an Iterable list const fruits = [' 🍎', ' 🍐', ' 🍊']; Iterator, is a pointer for traversing the elements of a data structure. // Creating an Iterator ‘fruitIterator’ const fruitIterator = fruits[Symbol.iterator]();
  • 3. Iterator object has a next() method which returns the next item in the sequence. This method returns an object with two properties, done and value. When next() call reaches to the end of sequence then the done property set to true else remain false. fruitIterator.next(); // {value: " 🍎", done: false} fruitIterator.next(); // {value: " 🍐", done: false} fruitIterator.next(); // {value: " 🍊", done: false} // Returns done as true when there is no element to return fruitIterator.next(); // {value: undefined, done: true}
  • 4. Without iterable, it is really difficult to manage the iteration on data for various types of data structures. For instance, iteration on an Array is different from iteration on an Object. And now with the introduction of new data structures like Sets and Maps in ES6, it is really going to be more complicated. Two things to look for while using iterables, Data consumer - How the iteration takes place. (Loops, Spread operator, Array.from method, Destructuring via an array pattern, etc.) Data source - What data structure we choose. (Array, Objects, Set, Maps, etc.) But, do we really need an iterable?