SlideShare a Scribd company logo
Iterators | ES6
JAGADEESH PATTA ( PJ )
Agenda
 Introduction Iterators
 Iterator on Array
 Iterator on Set
 Iterator on Object
 Live Examples
Introduction
 An object is consider like an iterable when it has an implementation for
Symbol.iterator property.
 When an object contains Symbol.iterator implementation than the object
allows us to use in for…of on it.
 Array, Map, Set and String have their Symbol.iterator property already
implemented.
Iterator on Array
 An array has its own iterator function implementation.
Example
var arr_one = [ 1, 2, 3, 4, 5 ];
for ( let element of arr_one){
console.log ( arr_one [ element ] );
}
Iterator on Set
 An set has its own iterator function implementation.
Example
var set_one = ( [ 1, 2, 3, 4, 5 ] );
for ( let element of set_one){
console.log ( set_one [ element ] );
}
Iterator on Object
 An object doesn’t have its own iterator function implementation. If we want to
apply for…of on object we need to implement Symbol.iterator.
Example
var obj = {
“name” : “PJ”, “designation” : “SSE”
}
Iterator on Object (cont…)
Custom Iterator
obj [ Symbol.iterator ] = function( ) {
let keys = Object.keys (obj), count = 0, isDone = false;
let next = ( ) => {
if ( count >= keys.length ) { isDone = true }
return { done : isDone, value : obj [ keys [ count++ ] ] };
} return { next };
}
Iterator on Object (cont…)
Custom Iterator
for ( let property of obj ) {
console.log ( obj [ property ] );
}
// PJ, SSE
Any Q ?
Thank You

More Related Content

What's hot (20)

PPT
An adaptive algorithm for detection of duplicate records
Likan Patra
 
PDF
haskell_fp1
Sambaiah Kilaru
 
PPTX
Python for lab_folk
Anneke Batenburg
 
PDF
Scala Collections : Java 8 on Steroids
François Garillot
 
PPT
Chapter 7 String
OUM SAOKOSAL
 
PPTX
FSTREAM,ASSERT LIBRARY & CTYPE LIBRARY.
Meghaj Mallick
 
PDF
IRJET- Soft Hyperfilters in Hyperlattices
IRJET Journal
 
PDF
Scipy, numpy and friends
Michele Mattioni
 
PPTX
Chapter 17 Tuples
Praveen M Jigajinni
 
PPT
Heapsort
zafarali5454
 
PDF
Arrays Java
Jose Sumba
 
PDF
Introduction to Loc
Ider Zheng
 
PDF
CDAT - cdms numpy arrays - Introduction
Arulalan T
 
PPTX
L13 string handling(string class)
teach4uin
 
PDF
Ms Ajax Array Extensions
jason hu 金良胡
 
PPT
lecture 5
sajinsc
 
PPTX
Arrays in Data Structure and Algorithm
KristinaBorooah
 
PPTX
Array of pointer
fasalsial1fasalsial1
 
PDF
Lecture 7- Iterator and for loop over arrays
Syed Afaq Shah MACS CP
 
PPTX
Stack Data structure
B Liyanage Asanka
 
An adaptive algorithm for detection of duplicate records
Likan Patra
 
haskell_fp1
Sambaiah Kilaru
 
Python for lab_folk
Anneke Batenburg
 
Scala Collections : Java 8 on Steroids
François Garillot
 
Chapter 7 String
OUM SAOKOSAL
 
FSTREAM,ASSERT LIBRARY & CTYPE LIBRARY.
Meghaj Mallick
 
IRJET- Soft Hyperfilters in Hyperlattices
IRJET Journal
 
Scipy, numpy and friends
Michele Mattioni
 
Chapter 17 Tuples
Praveen M Jigajinni
 
Heapsort
zafarali5454
 
Arrays Java
Jose Sumba
 
Introduction to Loc
Ider Zheng
 
CDAT - cdms numpy arrays - Introduction
Arulalan T
 
L13 string handling(string class)
teach4uin
 
Ms Ajax Array Extensions
jason hu 金良胡
 
lecture 5
sajinsc
 
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Array of pointer
fasalsial1fasalsial1
 
Lecture 7- Iterator and for loop over arrays
Syed Afaq Shah MACS CP
 
Stack Data structure
B Liyanage Asanka
 

Similar to 11. Iterators | ES6 | JavaScript | TypeScript (20)

PPTX
Iterable, iterator, generator by gaurav khurana
Gaurav Khurana
 
PDF
Iterables and Iterators in JavaScript
Ideas2IT Technologies
 
PDF
ES2015 (ES6) Overview
hesher
 
PPTX
ECMAScript 2015: my favourite parts
André Duarte
 
PPTX
Es6 day2
Abhishek Sharma
 
PDF
JavaScript Iteration Protocols - Workshop NodeConf EU 2022
Luciano Mammino
 
ODP
EcmaScript 6
Manoj Kumar
 
ODP
ES6 PPT FOR 2016
Manoj Kumar
 
PDF
ECMAScript 6
偉格 高
 
PDF
Javascript: repetita iuvant
Luciano Mammino
 
PDF
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
Igalia
 
PPTX
Iterators & Generators in ECMAScript 6.0
Eyal Vardi
 
PDF
Internal workshop es6_2015
Miguel Ruiz Rodriguez
 
PPTX
EcmaScript unchained
Eduard Tomàs
 
PPTX
ES6: Features + Rails
Santosh Wadghule
 
PPTX
Academy PRO: ES2015
Binary Studio
 
PDF
Workshop 10: ECMAScript 6
Visual Engineering
 
PDF
A, B, C. 1, 2, 3. Iterables you and me - Willian Martins (ebay)
Shift Conference
 
PDF
ECMAScript 6 Review
Sperasoft
 
Iterable, iterator, generator by gaurav khurana
Gaurav Khurana
 
Iterables and Iterators in JavaScript
Ideas2IT Technologies
 
ES2015 (ES6) Overview
hesher
 
ECMAScript 2015: my favourite parts
André Duarte
 
Es6 day2
Abhishek Sharma
 
JavaScript Iteration Protocols - Workshop NodeConf EU 2022
Luciano Mammino
 
EcmaScript 6
Manoj Kumar
 
ES6 PPT FOR 2016
Manoj Kumar
 
ECMAScript 6
偉格 高
 
Javascript: repetita iuvant
Luciano Mammino
 
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
Igalia
 
Iterators & Generators in ECMAScript 6.0
Eyal Vardi
 
Internal workshop es6_2015
Miguel Ruiz Rodriguez
 
EcmaScript unchained
Eduard Tomàs
 
ES6: Features + Rails
Santosh Wadghule
 
Academy PRO: ES2015
Binary Studio
 
Workshop 10: ECMAScript 6
Visual Engineering
 
A, B, C. 1, 2, 3. Iterables you and me - Willian Martins (ebay)
Shift Conference
 
ECMAScript 6 Review
Sperasoft
 
Ad

More from pcnmtutorials (18)

PPTX
12. Map | WeakMap | ES6 | JavaScript | Typescript
pcnmtutorials
 
PDF
10. symbols | ES6 | JavaScript | TypeScript
pcnmtutorials
 
PPTX
9. ES6 | Let And Const | TypeScript | JavaScript
pcnmtutorials
 
PPTX
8. Spread Syntax | ES6 | JavaScript
pcnmtutorials
 
PPTX
7. Rest parameters | ES6 | JavaScript
pcnmtutorials
 
PPTX
6. Default parameters | ES6 | JavaScript
pcnmtutorials
 
PPTX
5. Destructuring | ES6 | Assignment
pcnmtutorials
 
PPTX
4. Template strings | ES6
pcnmtutorials
 
PPTX
3. Object literals | ES6 | JSON
pcnmtutorials
 
PPTX
2. Classes | Object Oriented Programming in JavaScript | ES6 | JavaScript
pcnmtutorials
 
PPTX
1. Arrow Functions | JavaScript | ES6
pcnmtutorials
 
PPTX
Decorators | TypeScript | Angular2 Decorators
pcnmtutorials
 
PPTX
Web workers | JavaScript | HTML API
pcnmtutorials
 
PPTX
Declaration merging | Typescript
pcnmtutorials
 
PPTX
Module resolution | Typescript
pcnmtutorials
 
PPTX
Material design in android L developer Preview
pcnmtutorials
 
PPT
data structure, stack, stack data structure
pcnmtutorials
 
PPTX
1.introduction to data_structures
pcnmtutorials
 
12. Map | WeakMap | ES6 | JavaScript | Typescript
pcnmtutorials
 
10. symbols | ES6 | JavaScript | TypeScript
pcnmtutorials
 
9. ES6 | Let And Const | TypeScript | JavaScript
pcnmtutorials
 
8. Spread Syntax | ES6 | JavaScript
pcnmtutorials
 
7. Rest parameters | ES6 | JavaScript
pcnmtutorials
 
6. Default parameters | ES6 | JavaScript
pcnmtutorials
 
5. Destructuring | ES6 | Assignment
pcnmtutorials
 
4. Template strings | ES6
pcnmtutorials
 
3. Object literals | ES6 | JSON
pcnmtutorials
 
2. Classes | Object Oriented Programming in JavaScript | ES6 | JavaScript
pcnmtutorials
 
1. Arrow Functions | JavaScript | ES6
pcnmtutorials
 
Decorators | TypeScript | Angular2 Decorators
pcnmtutorials
 
Web workers | JavaScript | HTML API
pcnmtutorials
 
Declaration merging | Typescript
pcnmtutorials
 
Module resolution | Typescript
pcnmtutorials
 
Material design in android L developer Preview
pcnmtutorials
 
data structure, stack, stack data structure
pcnmtutorials
 
1.introduction to data_structures
pcnmtutorials
 
Ad

Recently uploaded (20)

PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
July Patch Tuesday
Ivanti
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
July Patch Tuesday
Ivanti
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 

11. Iterators | ES6 | JavaScript | TypeScript

  • 2. Agenda  Introduction Iterators  Iterator on Array  Iterator on Set  Iterator on Object  Live Examples
  • 3. Introduction  An object is consider like an iterable when it has an implementation for Symbol.iterator property.  When an object contains Symbol.iterator implementation than the object allows us to use in for…of on it.  Array, Map, Set and String have their Symbol.iterator property already implemented.
  • 4. Iterator on Array  An array has its own iterator function implementation. Example var arr_one = [ 1, 2, 3, 4, 5 ]; for ( let element of arr_one){ console.log ( arr_one [ element ] ); }
  • 5. Iterator on Set  An set has its own iterator function implementation. Example var set_one = ( [ 1, 2, 3, 4, 5 ] ); for ( let element of set_one){ console.log ( set_one [ element ] ); }
  • 6. Iterator on Object  An object doesn’t have its own iterator function implementation. If we want to apply for…of on object we need to implement Symbol.iterator. Example var obj = { “name” : “PJ”, “designation” : “SSE” }
  • 7. Iterator on Object (cont…) Custom Iterator obj [ Symbol.iterator ] = function( ) { let keys = Object.keys (obj), count = 0, isDone = false; let next = ( ) => { if ( count >= keys.length ) { isDone = true } return { done : isDone, value : obj [ keys [ count++ ] ] }; } return { next }; }
  • 8. Iterator on Object (cont…) Custom Iterator for ( let property of obj ) { console.log ( obj [ property ] ); } // PJ, SSE