how to create a map using js in javascript

index.tsx
// Creating a Map in JavaScript
let myMap = new Map();

// Adding elements to the map
myMap.set('key1', 'value1');
myMap.set('key2', 'value2');

// Accessing elements from the map
console.log(myMap.get('key1')); // Output: value1

// Checking if key exists in the map
console.log(myMap.has('key2')); // Output: true

// Deleting an element from the map
myMap.delete('key1');

// Getting the size of the map
console.log(myMap.size); // Output: 1

// Clearing the map
myMap.clear();
481 chars
22 lines

related categories

gistlibby LogSnag