Open In App

JavaScript Map keys() Method

Last Updated : 15 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The Map.keys() method is used to extract the keys from a given map object and return the iterator object of keys. The keys are returned in the order they were inserted.

Syntax:

Map.keys()

Parameters:

  • This method does not accept any parameters.

Return Value:

  • This returns the iterator object that contains keys in the map.

Example 1: Below is the basic example of the Map.keys() method.

Output:

MapIterator {"a", "b", "c"}

Example 2: In this example, we will create an object and print its keys in the console.

Output:

Type of mp.keys() is:  object
Keys in map mp are: MapIterator {'a', 'b', 'c', 'd'}

Example 3: Updating the value of the key in the map and printing values using the iterator object.

Output: 

MapIterator {'q', 'w', 'd', 'c'}
q
w

Supported Browsers:

  • Chrome
  • Opera
  • Edge
  • Firefox
  • Safari

Explore