Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Hashes/HashMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Creating a new Map
let myMap = new Map();

// Adding key-value pairs to the hashmap
myMap.set("name", "Rahul");
myMap.set("age", 22);
myMap.set("city", "Delhi");

// Accessing values using keys
console.log("Name:", myMap.get("name")); // Output: Name: Rahul
console.log("Age:", myMap.get("age")); // Output: Age: 22
console.log("City:", myMap.get("city")); // Output: City: Delhi

// Checking if a key exists in the hashmap
console.log(myMap.has("gender")); // Output: false

// Removing a key-value pair from the hashmap
myMap.delete("age");

// Iterating over key-value pairs in the hashmap
console.log("Iterating over key-value pairs:");
myMap.forEach((value, key) => {
console.log(`${key}: ${value}`);
});

// Output after deletion:
// Iterating over key-value pairs:
// name: Rahul
// city: Delhi