SlideShare a Scribd company logo
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

Similar to Iterables and Iterators in JavaScript (20)

PPTX
11. Iterators | ES6 | JavaScript | TypeScript
pcnmtutorials
 
PDF
JavaScript Iteration Protocols - Workshop NodeConf EU 2022
Luciano Mammino
 
PDF
Javascript: repetita iuvant
Luciano Mammino
 
ODP
ES6 PPT FOR 2016
Manoj Kumar
 
PPTX
Iterable, iterator, generator by gaurav khurana
Gaurav Khurana
 
PDF
A, B, C. 1, 2, 3. Iterables you and me - Willian Martins (ebay)
Shift Conference
 
PPTX
Es6 day2
Abhishek Sharma
 
PPTX
Academy PRO: ES2015
Binary Studio
 
PPTX
ECMAScript 2015: my favourite parts
André Duarte
 
ODP
EcmaScript 6
Manoj Kumar
 
PDF
The Lesser Known Features of ECMAScript 6
Bryan Hughes
 
PPTX
The ES Library for JavaScript Developers
Ganesh Bhosale
 
PPTX
ECMA5 and ES6 Promises
Oswald Campesato
 
PDF
ECMAScript 6 Review
Sperasoft
 
PDF
Internal workshop es6_2015
Miguel Ruiz Rodriguez
 
PDF
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
Igalia
 
PDF
JavaScript in 2016
Codemotion
 
PPTX
JavaScript in 2016 (Codemotion Rome)
Eduard Tomàs
 
PDF
Introduction to ES2015
kiranabburi
 
PDF
ES2015 (ES6) Overview
hesher
 
11. Iterators | ES6 | JavaScript | TypeScript
pcnmtutorials
 
JavaScript Iteration Protocols - Workshop NodeConf EU 2022
Luciano Mammino
 
Javascript: repetita iuvant
Luciano Mammino
 
ES6 PPT FOR 2016
Manoj Kumar
 
Iterable, iterator, generator by gaurav khurana
Gaurav Khurana
 
A, B, C. 1, 2, 3. Iterables you and me - Willian Martins (ebay)
Shift Conference
 
Es6 day2
Abhishek Sharma
 
Academy PRO: ES2015
Binary Studio
 
ECMAScript 2015: my favourite parts
André Duarte
 
EcmaScript 6
Manoj Kumar
 
The Lesser Known Features of ECMAScript 6
Bryan Hughes
 
The ES Library for JavaScript Developers
Ganesh Bhosale
 
ECMA5 and ES6 Promises
Oswald Campesato
 
ECMAScript 6 Review
Sperasoft
 
Internal workshop es6_2015
Miguel Ruiz Rodriguez
 
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
Igalia
 
JavaScript in 2016
Codemotion
 
JavaScript in 2016 (Codemotion Rome)
Eduard Tomàs
 
Introduction to ES2015
kiranabburi
 
ES2015 (ES6) Overview
hesher
 

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
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
 
PDF
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
 
PPTX
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
PDF
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
PDF
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
PPTX
ManageIQ - Sprint 264 Review - Slide Deck
ManageIQ
 
PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
PPTX
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
PPTX
WYSIWYG Web Builder Crack 2025 – Free Download Full Version with License Key
HyperPc soft
 
PDF
Rewards and Recognition (2).pdf
ethan Talor
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PDF
>Wondershare Filmora Crack Free Download 2025
utfefguu
 
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
 
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
 
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
ManageIQ - Sprint 264 Review - Slide Deck
ManageIQ
 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
WYSIWYG Web Builder Crack 2025 – Free Download Full Version with License Key
HyperPc soft
 
Rewards and Recognition (2).pdf
ethan Talor
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
>Wondershare Filmora Crack Free Download 2025
utfefguu
 
Ad

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?