What is Map.keys method in JavaScript?

The keys method of the Map object will return the keys of all the map entries.

Syntax


mapObj.keys()

Returns

The keys() method will return an iterator object. The returned iterator object contains all the keys of the map in the insertion order.

Code

Error: Code Widget Crashed, Please Contact Support

Explanation

In the code above:

  • We have created a Map object and added some entries to it.

  • Then called the keys method to get all the keys of the map objects.

  • Then printed the iterator object returned by the keys method using the for...of loop.

Free Resources