Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create HashMap.js #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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