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
Examples from Pune meetup
Santosh Ojha
 
PPTX
Flex box
Harish Karthick
 
PDF
jQuery - Chapter 4 - DOM Handling
WebStackAcademy
 
PDF
Sql Injection Myths and Fallacies
Karwin Software Solutions LLC
 
PDF
[Community Open Camp] 給 PHP 開發者的 VS Code 指南
Shengyou Fan
 
PPTX
Making Java more dynamic: runtime code generation for the JVM
Rafael Winterhalter
 
PPTX
Introduction to Node.js
Vikash Singh
 
PDF
Collections In Java
Binoj T E
 
PPTX
Express js
Manav Prasad
 
PPTX
History Of JAVA
ARSLANAHMED107
 
PPTX
Presentation1
Anand Grewal
 
PPTX
Advance OOP concepts in Python
Sujith Kumar
 
KEY
Web API Basics
LearnNowOnline
 
PDF
De Java 8 a Java 17
Víctor Leonel Orozco López
 
PDF
Introduction to Coroutines @ KotlinConf 2017
Roman Elizarov
 
PPTX
Java program structure
Mukund Kumar Bharti
 
PPTX
Core java complete ppt(note)
arvind pandey
 
PPTX
Inheritance in java
yash jain
 
PPTX
Advance Java Programming (CM5I) 6.Servlet
Payal Dungarwal
 
PPT
Javascript dom event
Bunlong Van
 
Examples from Pune meetup
Santosh Ojha
 
Flex box
Harish Karthick
 
jQuery - Chapter 4 - DOM Handling
WebStackAcademy
 
Sql Injection Myths and Fallacies
Karwin Software Solutions LLC
 
[Community Open Camp] 給 PHP 開發者的 VS Code 指南
Shengyou Fan
 
Making Java more dynamic: runtime code generation for the JVM
Rafael Winterhalter
 
Introduction to Node.js
Vikash Singh
 
Collections In Java
Binoj T E
 
Express js
Manav Prasad
 
History Of JAVA
ARSLANAHMED107
 
Presentation1
Anand Grewal
 
Advance OOP concepts in Python
Sujith Kumar
 
Web API Basics
LearnNowOnline
 
De Java 8 a Java 17
Víctor Leonel Orozco López
 
Introduction to Coroutines @ KotlinConf 2017
Roman Elizarov
 
Java program structure
Mukund Kumar Bharti
 
Core java complete ppt(note)
arvind pandey
 
Inheritance in java
yash jain
 
Advance Java Programming (CM5I) 6.Servlet
Payal Dungarwal
 
Javascript dom event
Bunlong Van
 

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
 
PDF
RxJS Operators - Real World Use Cases (FULL VERSION)
Tracy Lee
 
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
 
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
 
RxJS Operators - Real World Use Cases (FULL VERSION)
Tracy Lee
 
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
 
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)

PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
July Patch Tuesday
Ivanti
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
July Patch Tuesday
Ivanti
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 

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 ) );