0% found this document useful (0 votes)
19 views

JavaScript_Maps_Presentation

Uploaded by

Abishek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

JavaScript_Maps_Presentation

Uploaded by

Abishek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Manipulating and Accessing Map

Data Types in JavaScript


Team Members: [Your Names]
Date: [Presentation Date]
Introduction
• • What are Maps in JavaScript?
• - A collection of key-value pairs.
• - Keys can be of any data type.
• - Maintains insertion order.
• • Why Use Maps?
• - Efficient data retrieval.
• - More versatile than objects for key-value
mapping.
Creating a Map
• Code Example:
• const myMap = new Map();

• Adding Entries:
• myMap.set('key1', 'value1');
• myMap.set('key2', 'value2');
Accessing Map Data
• • Getting Values:
• const value = myMap.get('key1');

• • Checking Keys:
• myMap.has('key1'); // true

• • Size of the Map:


• myMap.size; // 2
Iterating Over Maps
• • Using forEach:
• myMap.forEach((value, key) => {
• console.log(key, value);
• });

• • Using for...of:
• for (const [key, value] of myMap) {
• console.log(key, value);
• }
Modifying Maps
• • Deleting Entries:
• myMap.delete('key1');

• • Clearing the Map:


• myMap.clear();
Use Cases of Maps
• • Storing user sessions.
• • Tracking inventory in e-commerce.
• • Caching results of computations.
Advantages of Maps
• • Compared to Objects:
• - Keys can be any type, including objects and
functions.
• - Preserves the order of insertion.
• - Easier size determination using `.size`.
Practical Example
• Task: Counting word frequency in a string.

• const wordCount = new Map();


• const words = 'hello world hello'.split(' ');
• words.forEach(word => {
• wordCount.set(word, (wordCount.get(word)
|| 0) + 1);
• });
• console.log(wordCount); // Map(2) { 'hello' =>
Conclusion
• • Key Points:
• - Maps are flexible and powerful for
managing key-value pairs.
• - Provide better performance and more
features compared to objects.

• • Questions?

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy