find the values of a map in javascript

To find the values of a map in JavaScript, we can iterate over the map object using its keys() method and access the values using its get() method. Here is an example:

index.tsx
// create a new map
const myMap = new Map();

// add some key-value pairs
myMap.set('key1', 'value1');
myMap.set('key2', 'value2');
myMap.set('key3', 'value3');

// access the values of the map
for (const key of myMap.keys()) {
  const value = myMap.get(key);
  console.log(value);
}
284 chars
14 lines

In this example, we create a new map myMap and add three key-value pairs to it. Then, we iterate over the keys of the map using a for-of loop and access the values of the map using the get() method. Finally, we log the values to the console.

Output:

index.tsx
value1
value2
value3
21 chars
4 lines

gistlibby LogSnag