To find the values of a Map in TypeScript, you can use the values()
method of the Map object. This method returns a new Iterator object that contains the values for each element in the Map object in insertion order. Here's an example:
index.ts156 chars10 lines
In this example, we first create a new Map object with three key-value pairs. We then use a for...of
loop to iterate over the values in the Map, logging each value to the console.
Alternatively, you can also use the forEach()
method of the Map object to iterate over the values. Here's an example:
index.ts147 chars10 lines
This code is functionally equivalent to the previous example, but uses the forEach()
method to iterate over the values in the Map.
gistlibby LogSnag