Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

map
keys
javascript
communitycreator

What is Map.keys method in JavaScript?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The keys method of the MapThe Map object is a collection of key-value pairs 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

let map = new Map();
map.set("one", 1);
map.set("two", 2);
map.set("three", 3);
let keyIterator = map.keys();
for(let key of keyIterator){
console.log(key)
}

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.

RELATED TAGS

map
keys
javascript
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring