To find the keys of a Map in TypeScript, you can use the keys()
method of the Map
object. This method returns an iterable containing the keys of the map, which you can then loop through using a for...of
loop or the forEach()
method.
Here's an example:
index.ts241 chars15 lines
In this example, we first create a Map
object called myMap
with two key-value pairs. We then loop through the map's keys using both a for...of
loop and the forEach()
method, logging the keys to the console.
Note that the keys()
method returns an iterable, meaning you can also use methods like Array.from()
or the spread operator (...
) to convert the iterable to an array if desired.
gistlibby LogSnag