SlideShare a Scribd company logo
Map, WeakMap | ES6
JAGADEESH PATTA ( PJ )
Agenda
 Introduction
 Object vs Map
 Map Syntax
 Method on Map
 Live Examples
 WeakMap
 WeakMap syntax
 Methods on WeakMap
 Live Example
Introduction
 The map object holds the data as key-value pair.
 The value may be any object or primitive data values.
 A map object iterates its elements in insertion order.
 Using for
of loop we can get key, values as an array for each iteration.
 We can give NaN as key in map.
Object vs Map
 Object allows keys only either strings or symbols. But map can allow any
type of data like primitives, functions, objects, etc.
 We can get values from object by using object[“key”] or object.key. But to
get values from map by using map.get(“key”) method.
 Data in the object can be any order. But in map the order of the keys based
on insertion of the data to map.
Syntax
Syntax
let map = new Map();
Example
let employeeMap = new Map();
Methods on Map
Clear( )
Delete( key )
Entries( )
Get( key )
Has( key )
Keys( )
Values( )
Set( key, val )
Insert Data into Map
let employeeMap = new Map( );
employeeMap.set(“empId”, 46);
employeeMap.set(“name”, “Jagadeesh”);
employeeMap.set(“designation”, “SSE”);
Get Data from Map
 Using forEach
 Using for
of
 Manual approach
Get Data from Map(cont
)
forEach
var map = new Map( );
map.forEach( function( key, val ){
console.log( key + “ “ + val );
});
Get Data from Map(cont
)
For
of
var map = new Map( );
for( let [ key, val ] of map ) {
console.log( key + “ “ + val );
}
Get Data from Map(cont
)
For
of ( cont
)
var map = new Map( );
for( let key of map.keys( ) ) {
console.log( key );
}
Get Data from Map(cont
)
For
of ( cont
)
var map = new Map( );
for( let val of map.values( ) ) {
console.log( val );
}
Get Data from Map(cont
)
For
of ( Cont
)
var map = new Map( );
for( let [ key, val ] of map.entries( ) ) {
console.log( key + “ “ + val );
}
Get Data from Map(cont
)
Manual
var map = new Map( );
console.log( map.get( key ) ); OR
var keys = map.keys( );
for ( let index = 0; index < keys.length; index++ ){
console.log( map.get( keys[ index ] ) );
}
WeakMap
 The weakmap object holds the data as key-value pair.
 In weakmap the keys are weakly referenced.
 The keys must be objects, and the values can be any values.
 We cannot get length of weakmap.
 Weakmap not allowed to get keys by keys() method.
Syntax
Syntax
let map = new WeakMap();
Example
let employeeMap = new WeakMap();
Methods on WeakMap
Delete( key )
Get( key )
Has( key )
Set( key, val )
WeakMap Example
let employeeMap = new WeakMap( );
var idObj = new Object( );
employeeMap.set( idObj, 46);
console.log( employeeMap.get( idObj ) );
Any Q ?
Thank You

More Related Content

What's hot (20)

PDF
[143] Modern C++ ëŹŽìĄ°ê±Ž 썚알 핮?
NAVER D2
 
PPTX
Hidden surface removal algorithm
KKARUNKARTHIK
 
PPTX
CSS Flexbox (flexible box layout)
Woodridge Software
 
PPTX
INTRODUCTION TO KEY FRAME SYSTEMS IN COMPUTER GRAPHICS
shalinikarunakaran1
 
PPTX
Dart and Flutter Basics.pptx
DSCVSSUT
 
PPTX
Css pseudo-classes
Webtech Learning
 
PPTX
TypeScript
Udaiappa Ramachandran
 
PDF
Computer graphics curves and surfaces (1)
RohitK71
 
PPTX
Javascript 101
Shlomi Komemi
 
PPTX
clippiNG COMPUTER GRAPHICS A NEW ERA.pptx
urvashipundir04
 
PPTX
Java script cookies
AbhishekMondal42
 
PPT
standard template library(STL) in C++
‱sreejith ‱sree
 
PPT
JavaScript Control Statements II
Reem Alattas
 
PPTX
Introduction to flexbox
Jyoti Gautam
 
PDF
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Andrew Rota
 
PPTX
Curve and text clipping
Arvind Kumar
 
PPTX
Clipping
nehrurevathy
 
PPTX
Media queries A to Z
Shameem Reza
 
PPT
Sr 01-40 good
manoj kumar reddy annapareddy
 
PPT
C++ classes tutorials
Mayank Jain
 
[143] Modern C++ ëŹŽìĄ°ê±Ž 썚알 핮?
NAVER D2
 
Hidden surface removal algorithm
KKARUNKARTHIK
 
CSS Flexbox (flexible box layout)
Woodridge Software
 
INTRODUCTION TO KEY FRAME SYSTEMS IN COMPUTER GRAPHICS
shalinikarunakaran1
 
Dart and Flutter Basics.pptx
DSCVSSUT
 
Css pseudo-classes
Webtech Learning
 
TypeScript
Udaiappa Ramachandran
 
Computer graphics curves and surfaces (1)
RohitK71
 
Javascript 101
Shlomi Komemi
 
clippiNG COMPUTER GRAPHICS A NEW ERA.pptx
urvashipundir04
 
Java script cookies
AbhishekMondal42
 
standard template library(STL) in C++
‱sreejith ‱sree
 
JavaScript Control Statements II
Reem Alattas
 
Introduction to flexbox
Jyoti Gautam
 
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Andrew Rota
 
Curve and text clipping
Arvind Kumar
 
Clipping
nehrurevathy
 
Media queries A to Z
Shameem Reza
 
C++ classes tutorials
Mayank Jain
 

Similar to 12. Map | WeakMap | ES6 | JavaScript | Typescript (20)

PDF
Mastering The Collections in JavaScript [Free Meetup]
Haim Michael
 
PPTX
Data Types and Processing in ES6
m0bz
 
PDF
New collections in JS: Map, Set, WeakMap, WeakSet - WarsawJS Meetup #25
Piotr Kowalski
 
PDF
Lecture notesmap
Vasanti Dutta
 
PPTX
Java Collections.pptx
AbhishekKudal2
 
PPTX
Things you can do in JavaScript ES6 that can't be done in ES5
Dan Shappir
 
PPTX
Session 20 - Collections - Maps
PawanMM
 
PPSX
Collections - Maps
Hitesh-Java
 
PPTX
Es6 day2
Abhishek Sharma
 
PDF
The map interface (the javaℱ tutorials collections interfaces)
charan kumar
 
PPTX
Lecture 11
talha ijaz
 
PDF
MCS First Year JavaScript ES6 Features.pdf
KavitaSawant18
 
PDF
Hash map (java platform se 8 )
charan kumar
 
PPTX
How Hashmap works internally in java
Ramakrishna Joshi
 
PPTX
Map reduce
Somesh Maliye
 
PPTX
Mapreduce introduction
Yogender Singh
 
PPTX
Map-Interface-and-HashMap-in-Java-A-Deep-Dive.pptx.pptx
iamzynix
 
PPTX
Dan Shappir: Things you can do in ES6 that can't be done in ES5
Danielle A Vincent
 
PPTX
Module3 for enginerring students ppt.pptx
mudduanjali02
 
Mastering The Collections in JavaScript [Free Meetup]
Haim Michael
 
Data Types and Processing in ES6
m0bz
 
New collections in JS: Map, Set, WeakMap, WeakSet - WarsawJS Meetup #25
Piotr Kowalski
 
Lecture notesmap
Vasanti Dutta
 
Java Collections.pptx
AbhishekKudal2
 
Things you can do in JavaScript ES6 that can't be done in ES5
Dan Shappir
 
Session 20 - Collections - Maps
PawanMM
 
Collections - Maps
Hitesh-Java
 
Es6 day2
Abhishek Sharma
 
The map interface (the javaℱ tutorials collections interfaces)
charan kumar
 
Lecture 11
talha ijaz
 
MCS First Year JavaScript ES6 Features.pdf
KavitaSawant18
 
Hash map (java platform se 8 )
charan kumar
 
How Hashmap works internally in java
Ramakrishna Joshi
 
Map reduce
Somesh Maliye
 
Mapreduce introduction
Yogender Singh
 
Map-Interface-and-HashMap-in-Java-A-Deep-Dive.pptx.pptx
iamzynix
 
Dan Shappir: Things you can do in ES6 that can't be done in ES5
Danielle A Vincent
 
Module3 for enginerring students ppt.pptx
mudduanjali02
 
Ad

More from pcnmtutorials (18)

PPTX
11. Iterators | 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
 
11. Iterators | 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)

PPTX
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
PDF
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PPTX
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
PDF
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PPTX
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
Practical Applications of AI in Local Government
OnBoard
 

12. Map | WeakMap | ES6 | JavaScript | Typescript

  • 1. Map, WeakMap | ES6 JAGADEESH PATTA ( PJ )
  • 2. Agenda  Introduction  Object vs Map  Map Syntax  Method on Map  Live Examples  WeakMap  WeakMap syntax  Methods on WeakMap  Live Example
  • 3. Introduction  The map object holds the data as key-value pair.  The value may be any object or primitive data values.  A map object iterates its elements in insertion order.  Using for
of loop we can get key, values as an array for each iteration.  We can give NaN as key in map.
  • 4. Object vs Map  Object allows keys only either strings or symbols. But map can allow any type of data like primitives, functions, objects, etc.  We can get values from object by using object[“key”] or object.key. But to get values from map by using map.get(“key”) method.  Data in the object can be any order. But in map the order of the keys based on insertion of the data to map.
  • 5. Syntax Syntax let map = new Map(); Example let employeeMap = new Map();
  • 6. Methods on Map Clear( ) Delete( key ) Entries( ) Get( key ) Has( key ) Keys( ) Values( ) Set( key, val )
  • 7. Insert Data into Map let employeeMap = new Map( ); employeeMap.set(“empId”, 46); employeeMap.set(“name”, “Jagadeesh”); employeeMap.set(“designation”, “SSE”);
  • 8. Get Data from Map  Using forEach  Using for
of  Manual approach
  • 9. Get Data from Map(cont
) forEach var map = new Map( ); map.forEach( function( key, val ){ console.log( key + “ “ + val ); });
  • 10. Get Data from Map(cont
) For
of var map = new Map( ); for( let [ key, val ] of map ) { console.log( key + “ “ + val ); }
  • 11. Get Data from Map(cont
) For
of ( cont
) var map = new Map( ); for( let key of map.keys( ) ) { console.log( key ); }
  • 12. Get Data from Map(cont
) For
of ( cont
) var map = new Map( ); for( let val of map.values( ) ) { console.log( val ); }
  • 13. Get Data from Map(cont
) For
of ( Cont
) var map = new Map( ); for( let [ key, val ] of map.entries( ) ) { console.log( key + “ “ + val ); }
  • 14. Get Data from Map(cont
) Manual var map = new Map( ); console.log( map.get( key ) ); OR var keys = map.keys( ); for ( let index = 0; index < keys.length; index++ ){ console.log( map.get( keys[ index ] ) ); }
  • 15. WeakMap  The weakmap object holds the data as key-value pair.  In weakmap the keys are weakly referenced.  The keys must be objects, and the values can be any values.  We cannot get length of weakmap.  Weakmap not allowed to get keys by keys() method.
  • 16. Syntax Syntax let map = new WeakMap(); Example let employeeMap = new WeakMap();
  • 17. Methods on WeakMap Delete( key ) Get( key ) Has( key ) Set( key, val )
  • 18. WeakMap Example let employeeMap = new WeakMap( ); var idObj = new Object( ); employeeMap.set( idObj, 46); console.log( employeeMap.get( idObj ) );